def fetch_mentions(self): url = "http://api.twitter.com/1/statuses/mentions.json?count=50" session = cherrypy.engine.publish('bind-session').pop() newest = Mention.newest(session) if newest: url += "&since_id=%d" % newest.tweet_id for user in User.all_(session): content = self.bus.publish("oauth-request", url, user.oauth_token, user.oauth_token_secret).pop() tweets = json.loads(content) if newest: cherrypy.log("Retrieved %d tweets since %s" % (len(tweets), newest.date)) else: cherrypy.log("Retrieved %d tweets" % (len(tweets), )) for tweet in tweets: user = tweet.get('user') if user: session.add( Mention(username=user['name'], user_id=user['id'], tweet=tweet['text'], tweet_id=tweet['id'], lang=self.guess_language(tweet['text']), date=parse(tweet['created_at']))) cherrypy.engine.publish('commit-session')
def fetch_mentions(self): url = "http://api.twitter.com/1/statuses/mentions.json?count=50" session = cherrypy.engine.publish('bind-session').pop() newest = Mention.newest(session) if newest: url += "&since_id=%d" % newest.tweet_id for user in User.all_(session): content = self.bus.publish("oauth-request", url, user.oauth_token, user.oauth_token_secret).pop() tweets = json.loads(content) if newest: cherrypy.log("Retrieved %d tweets since %s" % (len(tweets), newest.date)) else: cherrypy.log("Retrieved %d tweets" % (len(tweets), )) for tweet in tweets: user = tweet.get('user') if user: session.add(Mention(username=user['name'], user_id=user['id'], tweet=tweet['text'], tweet_id=tweet['id'], lang=self.guess_language(tweet['text']), date=parse(tweet['created_at']))) cherrypy.engine.publish('commit-session')