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_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