Example #1
0
    def post(self):
        from csrffilter import CSRFFilter
        
        user = users.get_current_user()
        mode = self.request.get('mode')

        #CSRF Protection
        filter = CSRFFilter(self, user)
        if not filter.checkCSRFToken():
            return filter.redirectCSRFWarning()

        user_prefs_query = UserPrefs.all()
        user_prefs_query.filter("google_id =", user)
        user_prefs = user_prefs_query.get()
        
        if user_prefs is not None:
            logging.info('Mode: %s' % mode)
            if mode == 'add':
                keyword = self.request.get('keyword')
                search_keywords = SearchKeywords()
                search_keywords.user_id = user_prefs.key()
                search_keywords.keyword = keyword
                search_keywords.put()
                
            elif mode == 'delete':
                deletes = self.request.get_all('deletes[]')
                for delete in deletes:
                    search_keywords = SearchKeywords.get_by_id(int(delete))
                    logging.info('Delete keyword: %s' % search_keywords.keyword)
                    if search_keywords is not None:
                        if search_keywords.user_id.key() == user_prefs.key():
                            search_keywords.delete()
        
        self.redirect('/config')
Example #2
0
    def post(self):
        from csrffilter import CSRFFilter

        user = users.get_current_user()
        mode = self.request.get('mode')

        #CSRF Protection
        filter = CSRFFilter(self, user)
        if not filter.checkCSRFToken():
            return filter.redirectCSRFWarning()

        user_prefs_query = UserPrefs.all()
        user_prefs_query.filter("google_id =", user)
        user_prefs = user_prefs_query.get()

        if user_prefs is not None:
            logging.info('Mode: %s' % mode)
            if mode == 'add':
                keyword = self.request.get('keyword')
                search_keywords = SearchKeywords()
                search_keywords.user_id = user_prefs.key()
                search_keywords.keyword = keyword
                search_keywords.put()

            elif mode == 'delete':
                deletes = self.request.get_all('deletes[]')
                for delete in deletes:
                    search_keywords = SearchKeywords.get_by_id(int(delete))
                    logging.info('Delete keyword: %s' %
                                 search_keywords.keyword)
                    if search_keywords is not None:
                        if search_keywords.user_id.key() == user_prefs.key():
                            search_keywords.delete()

        self.redirect('/config')
 def get(self):
     keyword_id = self.request.get('keyword_id')
     
     search_keywords = SearchKeywords.get_by_id(int(keyword_id))
     if search_keywords is not None:
         logging.info('Feed: %s' % search_keywords.keyword)
         
         user_prefs = UserPrefs().get_by_id(search_keywords.user_id.key().id())
         if user_prefs is not None:
             logging.info('Keyword owner name: %s' % user_prefs.google_id.nickname())
             if user_prefs.oauth_access_token_key is not None:
                 oauth_access_token = OAuthAccessToken.get_by_key_name(user_prefs.oauth_access_token_key.key().name())
                 if oauth_access_token is not None:
                     logging.info('Twitter Account: %s' % user_prefs.oauth_access_token_key.specifier)
                     try:
                         client = OAuthClient('twitter', self)
                         client.token = oauth_access_token
                         results = client.get('/search', q=search_keywords.keyword.encode('utf-8'))
                         for tweet_id in results['statuses']:
                             try:
                                 logging.info('Add taskqueue. tweet_id: %s' % tweet_id)
                                 taskqueue.add(url='/feed/tweet', method='GET', params={'tweet_id' : tweet_id, 'keyword_id': keyword_id})
                             except (taskqueue.Error, apiproxy_errors.Error):
                                 logging.exception('Failed to add taskqueue.')
                             
                     except Exception, error:
                         logging.error('Cache Failed: %s' % error)
Example #4
0
    def get(self):
        keyword_id = self.request.get('keyword_id')

        search_keywords = SearchKeywords.get_by_id(int(keyword_id))
        if search_keywords is not None:
            logging.info('Feed: %s' % search_keywords.keyword)

            user_prefs = UserPrefs().get_by_id(
                search_keywords.user_id.key().id())
            if user_prefs is not None:
                logging.info('Keyword owner name: %s' %
                             user_prefs.google_id.nickname())
                if user_prefs.oauth_access_token_key is not None:
                    oauth_access_token = OAuthAccessToken.get_by_key_name(
                        user_prefs.oauth_access_token_key.key().name())
                    if oauth_access_token is not None:
                        logging.info(
                            'Twitter Account: %s' %
                            user_prefs.oauth_access_token_key.specifier)
                        try:
                            client = OAuthClient('twitter', self)
                            client.token = oauth_access_token
                            results = client.get(
                                '/search',
                                q=search_keywords.keyword.encode('utf-8'))
                            for tweet_id in results['statuses']:
                                try:
                                    logging.info(
                                        'Add taskqueue. tweet_id: %s' %
                                        tweet_id)
                                    taskqueue.add(url='/feed/tweet',
                                                  method='GET',
                                                  params={
                                                      'tweet_id': tweet_id,
                                                      'keyword_id': keyword_id
                                                  })
                                except (taskqueue.Error,
                                        apiproxy_errors.Error):
                                    logging.exception(
                                        'Failed to add taskqueue.')

                        except Exception, error:
                            logging.error('Cache Failed: %s' % error)
 def get(self):
     tweet_id = self.request.get('tweet_id')
     keyword_id = self.request.get('keyword_id')
     
     search_keywords = SearchKeywords.get_by_id(int(keyword_id))
     if search_keywords is not None:
         logging.info('Feed: %s' % search_keywords.keyword)
         
         user_prefs = UserPrefs().get_by_id(search_keywords.user_id.key().id())
         if user_prefs is not None:
             logging.info('Keyword owner name: %s' % user_prefs.google_id.nickname())
             if user_prefs.oauth_access_token_key is not None:
                 oauth_access_token = OAuthAccessToken.get_by_key_name(user_prefs.oauth_access_token_key.key().name())
                 if oauth_access_token is not None:
                     logging.info('Twitter Account: %s' % user_prefs.oauth_access_token_key.specifier)
                     try:
                         search_cache_query = SearchCache().all()
                         search_cache_query.filter('tweet_id =', int(tweet_id))
                         search_cache_query.filter('keyword_key =', search_keywords.key())
                         if search_cache_query.get() is None:
                             client = OAuthClient('twitter', self)
                             client.token = oauth_access_token
                             tweet = client.get('/statuses/show/%d' % int(tweet_id))
                             
                             logging.info('Tweet: (%s) %s' % (tweet['user']['name'], tweet['text']))
                             logging.info(tweet['created_at'])
                             
                             search_cache = SearchCache()
                             search_cache.tweet_id = int(tweet_id)
                             search_cache.keyword_key = search_keywords.key()
                             search_cache.name = tweet['user']['name']
                             search_cache.screen_name = tweet['user']['screen_name']
                             search_cache.profile_image_url = tweet['user']['profile_image_url']
                             search_cache.text = tweet['text']
                             search_cache.location = tweet['user']['location']
                             search_cache.time_zone = tweet['user']['time_zone']
                             search_cache.tweeted_at = datetime.datetime.strptime(tweet['created_at'], "%a %b %d %H:%M:%S +0000 %Y")
                             search_cache.put()
                         else:
                             logging.info('Skip. tweet_id: %d' % int(tweet_id))
                             
                     except Exception, error:
                         logging.error('Cache Failed: %s' % error)
Example #6
0
    def get(self):
        tweet_id = self.request.get('tweet_id')
        keyword_id = self.request.get('keyword_id')

        search_keywords = SearchKeywords.get_by_id(int(keyword_id))
        if search_keywords is not None:
            logging.info('Feed: %s' % search_keywords.keyword)

            user_prefs = UserPrefs().get_by_id(
                search_keywords.user_id.key().id())
            if user_prefs is not None:
                logging.info('Keyword owner name: %s' %
                             user_prefs.google_id.nickname())
                if user_prefs.oauth_access_token_key is not None:
                    oauth_access_token = OAuthAccessToken.get_by_key_name(
                        user_prefs.oauth_access_token_key.key().name())
                    if oauth_access_token is not None:
                        logging.info(
                            'Twitter Account: %s' %
                            user_prefs.oauth_access_token_key.specifier)
                        try:
                            search_cache_query = SearchCache().all()
                            search_cache_query.filter('tweet_id =',
                                                      int(tweet_id))
                            search_cache_query.filter('keyword_key =',
                                                      search_keywords.key())
                            if search_cache_query.get() is None:
                                client = OAuthClient('twitter', self)
                                client.token = oauth_access_token
                                tweet = client.get('/statuses/show/%d' %
                                                   int(tweet_id))

                                logging.info(
                                    'Tweet: (%s) %s' %
                                    (tweet['user']['name'], tweet['text']))
                                logging.info(tweet['created_at'])

                                search_cache = SearchCache()
                                search_cache.tweet_id = int(tweet_id)
                                search_cache.keyword_key = search_keywords.key(
                                )
                                search_cache.name = tweet['user']['name']
                                search_cache.screen_name = tweet['user'][
                                    'screen_name']
                                search_cache.profile_image_url = tweet['user'][
                                    'profile_image_url']
                                search_cache.text = tweet['text']
                                search_cache.location = tweet['user'][
                                    'location']
                                search_cache.time_zone = tweet['user'][
                                    'time_zone']
                                search_cache.tweeted_at = datetime.datetime.strptime(
                                    tweet['created_at'],
                                    "%a %b %d %H:%M:%S +0000 %Y")
                                search_cache.put()
                            else:
                                logging.info('Skip. tweet_id: %d' %
                                             int(tweet_id))

                        except Exception, error:
                            logging.error('Cache Failed: %s' % error)