Ejemplo n.º 1
0
    def get(self):
        session = get_current_session()
        session['last_search_results'] = ''
        last_search_term = ''

        if ('last_search_term' in session):
            last_search_term = session['last_search_term']

        code = self.request.get('code')
        token = self.request.get('token')
        logging.info('Token in get request '+ token)
        logging.info(code)
        access_code = ''
	if (len(code) < 1):
          self.redirect("https://www.facebook.com/dialog/oauth?client_id=XXXX&scope=read_stream&redirect_uri=https://myfacebookwallsearch.appspot.com/init")
	
        #access_token=self.getAccessToken(code) 
        #session['access_token'] = access_token
        if ('access_token' in session):
           access_token = session['access_token']
           logging.info("Access token in session :" + access_token)
        else:
           access_token = self.getAccessToken(code)  
           session['access_token'] = access_token
 
        fbUser, fbName = self.getUsersIdAndFullNameByAccessToken(access_token)
        device = self.determine_device()
        audit.add_audit_record(fbUser,fbName,'web_login_page', self.request.remote_addr, device)
        session['user']=fbUser
        session['name']=fbName

        logging.info("Added user to session")
        fbqueryuser.addUserToDataStore(access_token)
        min_date, max_date = fbmessages.find_min_max_post_dates(fbUser)
        logging.info('Yes ... User added to the database')
        token = generateFormToken(access_token, fbUser)
        memcache.add(token, access_token)

        template_values = {
            'token': token,
            'userFullName' : fbName,
            'minDate' : min_date.strftime("%d-%m-%Y"),
            'maxDate' : max_date.strftime("%d-%m-%Y"),
            'last_search_term' : last_search_term
        }
	#template = jinja_environment.get_template('indexfb.html')
        if self.determine_device() == 'Mobile':
            template = jinja_environment.get_template('app.html')
        else:
            template = jinja_environment.get_template('new_home.html')
        deferred.defer(do_async_call_to_cache_wall, access_token ,fbUser ,fbName , 0)
        #logging.info("Async call made")
        self.response.out.write(template.render(template_values))
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
 def get(self):
     device = self.determine_device()
     search_term = self.request.get('searchbox')
     access_token, fb_user, fb_name = self.pull_data_from_session()
     audit.add_audit_record(fb_user,fb_name,'search_page', self.request.remote_addr, device)
     long_lived_token = fbtokenutil.genLongLivedAccessToken(fb_user,access_token)
     posts_matching_search = fbmessages.find_search_term(search_term ,fb_user, self.is_mobile_request())
     results = fbmessages.to_serializable_list(posts_matching_search)
     min_date, max_date = fbmessages.find_min_max_post_dates(fb_user)                
     template_values = {'last_search_term': search_term, 
                        'results': self.handle_no_results_found(results),
                        'minDate': min_date.strftime("%d-%m-%Y"),
                        'maxDate': max_date.strftime("%d-%m-%Y") }
     template = jinja_environment.get_template('app.html')
     self.response.out.write(template.render(template_values))
Ejemplo n.º 4
0
    def post(self):
        logging.info('In HTTP POST method of main page')
        signed_request = self.request.get('signed_request')
        signature,data = signed_request.split('.')
        data += "=" * (len(data) - 4)
        logging.info('Signed Request ' + signed_request)
        if (signed_request is not None and signed_request is not ''):
          logging.info('Signed request populated. About to base64 decode it')
          base_decoded_data = base64.b64decode(data)
          logging.info('Base 64 decoded in facebook embedded app' + base_decoded_data)
          jsondata=json.loads(base_decoded_data)
          logging.info(jsondata)
          
          if 'oauth_token' in jsondata:
            logging.info("Request coming in from apps.facebook")
            session = get_current_session()
            last_search_term = ''
            if ('last_search_term' in session):
                last_search_term = session['last_search_term']
            
            access_token = jsondata['oauth_token']
            logging.info('OAuth token' + jsondata['oauth_token'])
            fbUser, fbName = fbqueryuser.getFbUserDetails(jsondata['oauth_token'])
            session['user'] = fbUser
            session['name'] = fbName
            fbqueryuser.addUserToDataStore(jsondata['oauth_token'])
            token = generateFormToken(access_token, fbUser)
            device = self.determine_device()
            audit.add_audit_record(fbUser,fbName,'fb_canvas_login_page', self.request.remote_addr, device)
            min_date, max_date = fbmessages.find_min_max_post_dates(fbUser)
            memcache.add(token, access_token)
            template_values = {
              'token': token,
              'userFullName' : fbName,
              'minDate' : min_date.strftime("%d-%m-%Y"),
              'maxDate' : max_date.strftime("%d-%m-%Y"),
              'last_search_term' : last_search_term
             }
	    #template = jinja_environment.get_template('indexfb.html')
            template = jinja_environment.get_template('new_home.html')
            self.response.out.write(template.render(template_values))
          else:
            login_url="https://www.facebook.com/dialog/oauth?client_id=XXX&scope=read_stream&redirect_uri=https://apps.facebook.com/srchfeeds/"
            self.response.out.write("<script> top.location.href='" + login_url +"'</script>")
Ejemplo n.º 5
0
  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)
Ejemplo n.º 6
0
    def post(self):
        session = get_current_session()
        signed_request = self.request.get('signed_request')
        logging.info('Signed Request ' + signed_request)

        if (signed_request is not None and signed_request is not ''):
          logging.info('Signed request populated. About to base64 decode it')
          base_encoded_data = base64.b64decode(signed_request)
          logging.info(base_encoded_data)
          self.response.out.write('Base 64 decoded ' + base_encoded_data)
        else:
          session['last_search_results'] = ''
          search_terms = self.request.get('search_terms')
          session['last_search_term'] = search_terms
          logging.info(search_terms)
          max_posts = self.request.get('max_posts')
          logging.info(max_posts)
          token = self.request.get('token')
          logging.info(token)
          accessToken = memcache.get(token)      
          fbUser, fbName = self.getUsersIdAndFullNameByAccessToken(accessToken)
          device = self.determine_device()
          audit.add_audit_record(fbUser,fbName,'search_page', self.request.remote_addr, device)
          long_lived_token = fbtokenutil.genLongLivedAccessToken(fbUser,accessToken)
          logging.info("about to call a search ")
          #delete_results_of_last_search(gen_search_results_key(fbUser))
          posts_matching_search = fbmessages.find_search_term(search_terms ,fbUser, self.is_mobile_request())
          jsonResults = {}
          lst = fbmessages.to_serializable_list(posts_matching_search)
          if (len(lst) < 1):
              session['last_search_term'] = ''
          #cache_results_of_last_search(gen_search_results_key(fbUser),lst)
          jsonResults['matchingResults'] = lst
          listToJson = json.dumps(jsonResults);
          session['last_search_results'] = listToJson
          logging.info("Last search entry added to session")
          self.response.out.write(listToJson)