Ejemplo n.º 1
0
def get_keyword_tweets(keyword):
    print_msg("Checking if keyword exists...")
    tweets = []
    sk = models.SearchKeyword.get_keyword(keyword)
    if sk:
        for tweet in models.TweetModel.get_tweets_of_keyword(keyword):
            tweets.append(tweet.to_dict())
    print_msg("Done!")
    return tweets
Ejemplo n.º 2
0
def get_all_tweets_keywords():
    all_tweets = {}
    print_msg("Getting all tweets by any keyword...")
    for keyword in models.SearchKeyword.query.all():
        all_tweets[keyword.name] = []
        for tweet in models.TweetModel.get_tweets_of_keyword(keyword.name):
            all_tweets[keyword.name].append(tweet.to_dict())
    print_msg("Done!")
    return all_tweets
Ejemplo n.º 3
0
def search_tweets_by_keywords(keyword):
    ResultObjects = []
    try:
        for StatusObject in Cursor(api.search,
                                   q=keyword).items(MAXIMUM_SEARCH_RESULT):
            ResultObjects.append(parse_tweet_info(StatusObject))

    except Exception as e:
        print_msg(e)
    return ResultObjects
Ejemplo n.º 4
0
def get_top_tweets(option):
    print_msg("Getting top tweets")
    if option == 'retweet':
        query = 'retweet_count'
    elif option == 'like':
        query = 'favorite_count'

    tweets = []
    for tweet in models.TweetModel.query.order_by(query):
        tweets.insert(0, tweet.to_dict())
    print_msg("Done!")
    return tweets
Ejemplo n.º 5
0
def get_users_by_keyword(keyword):
    users = {}
    print_msg("Getting all users of keyword %s..." % (keyword))
    # TODO: Remove this and add group_by query
    for tweet in models.TweetModel.get_tweets_of_keyword(keyword):
        if tweet.author_id in users.keys():
            users[tweet.author_id]['count'] += 1
        else:
            users[tweet.author_id] = {
                "User ID": tweet.author_id,
                "count": 1,
            }
    print_msg("Done!")
    return users
Ejemplo n.º 6
0
def store_tweets_to_db(keyword, tweets):
    # TODO: store tweets to db
    print_msg("Storing tweets to database of keyword %s..." % (keyword))
    sk = models.SearchKeyword.get_keyword(keyword)
    if not sk:
        sk = models.SearchKeyword(keyword)

    for tweet in tweets:
        # print(tweet.get('id_str'))
        s_tweet = models.TweetModel.get_tweet(tweet.get('id_str'))
        if not s_tweet:
            tweetm = models.TweetModel(tweet)
            tweetm.keywords.append(sk)
            tweetm.save()
        else:
            s_tweet.update(sk)
    print_msg("Done!")
Ejemplo n.º 7
0
def get_tweets(keyword):
    # TODO: Fetch tweets of keywords from Twitter API
    print_msg("Authenticating user...")
    authenticate_user()
    print_msg("Done!")

    print_msg("Fetching tweets of keyword %s..." % (keyword))
    search_result_general = search_tweets_by_keywords(keyword)
    print_msg("Done!")

    return search_result_general
Ejemplo n.º 8
0
def delete_outdated_tweets(keyword):
    print_msg("Deleting existing tweets of keyword %s" %(keyword))
    models.TweetModel.delete_outdated_tweets(keyword)
    print_msg("Done!")
Ejemplo n.º 9
0
def get_outdated_keywords():
    print_msg("Fetching outdated keywords")
    return models.SearchKeyword.outdated_keywords()