def post(self): access_token = self.getToken() logging.info("This is the real time update post method being invoked") messageBody = self.request.body jsonData = json.loads(messageBody) logging.info(json.dumps(jsonData,sort_keys=True, indent=4)) data = jsonData['entry'] for i in data: fbUser = i['id'] who = fbqueryuser.getUserFullName(fbUser, access_token) logging.info("Whose wall changed " + who) #token = memcache.get(user+"long_lived") user = fbqueryuser.queryUserFromDataStore(fbUser) token = None if user is not None: token=user.long_lived_token if (token is not None): thisUsersWallUrl = "https://graph.facebook.com/"+ fbUser +"/home?access_token="+token+"&limit=99" logging.info(thisUsersWallUrl) fbUserWallContent = urlfetch.fetch(thisUsersWallUrl,deadline=20,headers = { 'Cache-Control': 'no-cache,max-age=0', 'Pragma': 'no-cache' }) wallData = json.loads(fbUserWallContent.content) if 'data' in wallData: data = wallData['data'] fbmessages.processGraphApiJsonMessage(fbUser ,who ,data, token) #logging.info(json.dumps(wallData,sort_keys=True, indent=4)) else: logging.info("User " + who + " does not have a long lived token")
def find_min_max_post_dates(fbUser): user = fbqueryuser.queryUserFromDataStore(fbUser) ''' if user is none its probably because the update hasnt been applied or it hasnt synchronized to all db nodes ''' if user is None: return datetime.now(), datetime.now() max_date = Posts.all().filter('owner =',fbUser).order('-post_datetime').fetch(1) if len(max_date) > 0: latest_post = max_date[0] return user.date_account_created,latest_post.post_datetime else: return datetime.now(), datetime.now()
def get(self): session = get_current_session() if 'user' in session: fb_id = session['user'] user = fbqueryuser.queryUserFromDataStore(fb_id) device = self.determine_device() audit.add_audit_record(user.facebook_id, user.displayName,'my_friends_tag_cloud_page', self.request.remote_addr, device) json = fbqueryuser.myfriends_are(fb_id) if 'data' in json: friends = json['data'] template_values = {'friends': friends} template = jinja_environment.get_template('tagcloudfriends.html') self.response.out.write(template.render(template_values))
def get(self): session = get_current_session() html = "" if 'user' in session: user_id = session['user'] posts = fbmessages.search_contents_for_tagcloud_page(user_id) user = fbqueryuser.queryUserFromDataStore(user_id) device = self.determine_device() audit.add_audit_record(user.facebook_id, user.displayName,'my_tag_cloud_page', self.request.remote_addr, device) post_list = [] logging.info("Count of words before stop words filter" + str(len(posts))) for i in range(0,len(posts)-1): if (posts[i] not in stopwords.stop_words()): post_list.append(posts[i]) c = collections.Counter(post_list) html = self.generate_html(c) else: logging.info("User id not found in session") self.response.out.write(html)