def fetch_snow_tweets(): logging.info("Fetching tweets for tag #uksnow") key = 'uksnow' feeditemcount = 1 latest_cached = 0 since_id = models.get_from_keystore(key) tweets = twitter.get_twitter_search('uksnow&filter=links', since_id) for tweet in tweets['results']: if feeditemcount == 1: try: latest_cached = str(tweet['id']) except: latest_cached = 0 taskqueue.add(url='/services/store_tweet', params={ 'userid': tweet['from_user_id'], 'username': tweet['from_user'], 'imgurl': tweet['profile_image_url'], 'message': tweet['text'], 'messageid': tweet['id'], 'message_created': tweet['created_at'], 'geo': tweet['geo'], }) feeditemcount += 1 if latest_cached > 0: models.add_to_keystore(key, latest_cached)
def get(self): key = 'last_id' keystore = KeyStore.get_by_key_name(key) last_id = keystore and keystore.value tweets = twitter.get_twitter_search('%23ukbeer', last_id) logger.info("Fetched %d tweets", len(tweets['results'])) for tweet in tweets['results']: deferred.defer(store_tweet, tweet) logger.debug(pformat(tweets)) last_id = tweets['max_id'] if last_id: keystore = KeyStore.get_or_insert(key, name=key) keystore.value = tweets['max_id_str'] keystore.put() self.response.out.write("Fetched %d tweets" % len(tweets['results']))
def get(self): tweets = twitter.get_twitter_search('%23ukbeer', '1') self.response.out.write(template.render('index.html', { 'tweets': tweets, }))