def post(self): logging.info("***rvlh") cookies = h.get_default_cookies(self) current_user = h.get_current_user(cookies) result_view = ResultView() result_view.source = self.request.get('src') result_view.referrer = self.request.get('referrer') result_view.url = self.request.get('u') result_view.ip_address = self.request.remote_addr result_view.image_url = self.request.get('image_url') result_view.query_string = self.request.get('q') #logging.info(" ".join((result_view.source, result_view.referrer, result_view.url, result_view.ip_address, # result_view.image_url, result_view.query_string))) if '_pvk' in cookies and cookies['_pvk'] != None and cookies['_pvk'] != '': result_view.session_id = cookies['_pvk'] if current_user != None: result_view.user = current_user if current_user.fb_user_id != None: result_view.fb_user_id = current_user.fb_user_id query = Query.gql( "WHERE user = :1 AND query_string = :2 ORDER BY created_at DESC", current_user.key(), self.request.get('q')).get() if query != None: result_view.query = query result_view.put() # Post to facebook wall for the query if the query hasn't already posted to wall if current_user != None and query != None and query.fb_wall_post_id == None: logging.info("***Posting") image_url = self.request.get('image_url') if not image_url: from google.appengine.api import urlfetch from django.utils import simplejson q = 'site:'+result_view.url+" "+result_view.query_string ue_query = urllib.quote_plus(q) url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q='\ +ue_query+'&key='\ +h.cfg['gs_api_key'] result = urlfetch.fetch(url) o = simplejson.loads(result.content) image_url = o['responseData']['results'][0]['tbUrl'] fb_post_id = QueryFacebookWallpostHelper.postToWallIfNecessary(current_user, result_view, query, image_url) self.response.out.write('{status: \'ok\', fb_wall_post_id: \'%s\', result_view_key: \'%s\'}' % (fb_post_id, str(result_view.key()))) else: # logging.info("***NoPost : "+current_user+" "+query+" "+query.fb_wall_post_id) self.response.out.write('{status: \'ok\', result_view_key: \'%s\', result_view_has_user: \'%s\'}' % (str(result_view.key()), str(current_user != None)))
def post(self): query = User.all() query.order('-created_at') cursor = self.request.get('cursor') if cursor != None: query.with_cursor(cursor) users = query.fetch(50) for user in users: user_queries = Query.gql("WHERE user = :1 ORDER BY created_at ASC", user).fetch(1000) user_search_strings = [] for user_query in user_queries: if user_query.url != None: parsed_url = urlparse(user_query.url) else: parsed_url = urlparse('') params = cgi.parse_qs(parsed_url.query) # Right now, we'll use the x (and y) param to signify an organic search. if 'x' in params and params['x'] != None: user_search_strings.append(user_query.query_string) organic_search_metric = OrganicSearchMetric.gql("WHERE user = :1", user).get() if organic_search_metric == None: organic_search_metric = OrganicSearchMetric( fb_user_id = user.fb_user_id, user = user, search_count = len(user_search_strings), searches = "||".join(user_search_strings) ) else: organic_search_metric.fb_user_id = user.fb_user_id organic_search_metric.user = user organic_search_metric.search_count = len(user_search_strings) organic_search_metric.searches = "||".join(user_search_strings) organic_search_metric.put() self.response.out.write(simplejson.dumps({'status': 'ok', 'cursor': str(query.cursor()), 'count': len(users) }))