def get(self): date = datetime.datetime.now() - datetime.timedelta(days=1) search_cache_query = SearchCache().all() search_cache_query.filter('tweeted_at <', date) search_cache_query.order('tweeted_at') search_cache = search_cache_query.fetch(100) logging.info('Delete old cache. count: %d' % len(search_cache)) for cache in search_cache: cache.delete()
def get(self): date = datetime.datetime.now() - datetime.timedelta(days=1) search_cache_query = SearchCache().all() search_cache_query.filter('tweeted_at <', date) search_cache_query.order('tweeted_at') search_cache = search_cache_query.fetch(100) logging.info('Delete old cache. count: %d' % len(search_cache)) for cache in search_cache: cache.delete()
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)
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)