def find_users(): usernames = {} all_tweets = twitter_lib.all_tweets() tweets_list = [] for tweet in all_tweets: tweets_list.append(tweet) usernames[tweet.username] = True for username in twitter_lib.find_mentions(tweet.text): usernames[username] = True twitter_lib.insert_users(usernames.keys()) return tweets_list
def find_tweet_userids(all_tweets): all_tweets = twitter_lib.all_tweets() users = twitter_lib.all_users() users_map = {} tweet_updates = [] for user in users: users_map[user.username] = user.sqlid for tweet in all_tweets: tweet.userid = users_map[tweet.username] tweet_updates.append(tweet) print 'size of all_tweets', len(tweet_updates) twitter_lib.update_tweet_userids(tweet_updates) return users_map
def find_mentions(users_map): print 'Finding mentions...' mentions = [] all_tweets = twitter_lib.all_tweets() tweets_list = [] for tweet in all_tweets: tweets_list.append(tweet) for mention in twitter_lib.find_mentions(tweet.text): # print 'found mention', tweet.sqlid, tweet.userid, mention mentions.append(twitter_lib.Mention(-1, tweet.sqlid, tweet.userid, mention)) print 'mentions found', str(len(mentions)) i = 0 for mention in mentions: if not mention.mentioned in users_map: #print 'Error, user not found, name', mention.mentioned pass else: mention.mentioned = users_map[mention.mentioned] twitter_lib.insert_mentions(mentions) return tweets_list