Example #1
0
def tweets_page():
    page = int(request.args.get('page', default = '1', type = int))
    nb_el = int(resources.NB_ITEMS_PER_PAGE)

    tweets = db.getInstance().get_tweets_paginated(page - 1, nb_el)
    nb_item = db.getInstance().get_number_of_tweets()

    #tweets = db.getInstance().get_tweets({})
    json_data = dumps(tweets)

    return render_template('datasetv2.html', tweets = json_data, page=page, nb_item=nb_item, per_page = nb_el)
Example #2
0
def tweet_page():
    tweet_id = request.args.get('id', default = '-1', type = str)
    tweet = db.getInstance().get_tweet_by_id(tweet_id)

    if tweet == None:
        return render_template('tweet-not-found.html'), 404

    json_data = dumps(tweet)
    return render_template('tweet.html', tweet_id=tweet.get('tweet_id'), username=tweet.get('user_screenname'), tweet= json_data)
Example #3
0
def route_default():
    positive = db.getInstance().get_top_positive_tweets({})
    negative = db.getInstance().get_top_negative_tweets({})
    json_positive = dumps(positive)
    json_negative = dumps(negative)
    total_tweets = db.getInstance().get_number_of_tweets()
    number_positive = db.getInstance().get_number_of_tweets_by_range("positive")
    number_neutral = db.getInstance().get_number_of_tweets_by_range("neutral")
    number_negative = db.getInstance().get_number_of_tweets_by_range("negative")
    listetags = db.getInstance().get_top_hashtags(20)


    return render_template('index.html', 
        positive_tweets = json_positive, 
        negative_tweets = json_negative,         
        count_tweets = total_tweets,
        count_positive = number_positive,
        count_negative = number_negative,
        count_neutral = number_neutral,
        hash = listetags
        )
Example #4
0
#from datatweet import tweet_manager
#from datatweet.tweet_manager import TweetCollection

if __name__ == "__main__":
    #print(resources.CONSUMER_SECRRET)
    product_name = "#XboxSeriesS"

    # test first 5 most recent tweets
    list_tweet = TweetCollection(
        resources.CONSUMER_KEY, resources.CONSUMER_SECRRET,
        resources.ACCESS_TOKEN,
        resources.ACCESS_TOKEN_SECRET).get_tweet_by_product(product_name)

    #    print("before getting the sentiment")
    for tweet in list_tweet:
        print(tweet.to_json())
        print("\n")

    list_sent_tweet = TweetSentimentPrediction(
        list_tweet, resources.SUBSCRIPTION_KEY,
        resources.SENTIMENT_ENDPOINT_URL).predict()

    #    print("after getting the sentiment")
    list_json = []
    for tweet in list_sent_tweet:
        print(tweet.to_json())
        list_json.append(tweet.to_json())
        print("\n")

    db.getInstance().add_many_tweets(list_json)
Example #5
0
from database.db_access import DatabaseManager as db

#test dataset
test = {'name': 'tweet1', 'sentiment': 2, 'text': 'random comment'}

#test singleton
try:
    singleton_test = db()
    singleton_test = db()
    assert False, 'you should not be able to instanciate Databasemanager twice'
except:
    assert True, 'not able to instanciate Databasemanager as expected'

#insert tweet
result = db.getInstance().add_one_tweet(test)
assert result, 'not able to insert the tweet'

#get all tweet
result = db.getInstance().get_tweets({})
#get id of the first tweet retrieved
tweet_test_id = result[0].get('_id')
print(tweet_test_id)

#get tweet by id
result = db.getInstance().get_tweet_by_id(tweet_test_id)
print(result)

#update tweet by id
result = db.getInstance().update_tweet_by_id(tweet_test_id, {'sentiment', 3})
print('record updated: ' + str(result))
Example #6
0
from database.db_access import DatabaseManager as db

if __name__ == "__main__":
    

    tweet_id = "1304045426715299846"

    print(db.getInstance().get_tweet_by_id(tweet_id) == None)

    print(db.getInstance().get_tweet_by_id('id') == None)
Example #7
0
from database.database_access import DatabaseManager
from configuration import resources

from database.db_access import DatabaseManager as db

if __name__ == "__main__":
    """
    mongo_instance = DatabaseManager(resources.MONGODB_USER
                                    , resources.MONGODB_PASSWORD
                                    , resources.MONGODB_SERVER)

    for data in mongo_instance.get
    """
    dict_tag = {}
    for tweet in db.getInstance().get_tweets({}):
        list_tag = tweet['entities']['hashtags']
        for tag in list_tag:
            text = tag['text']
            if (not text in dict_tag):
                dict_tag[text] = 1
            else:
                dict_tag[text] += 1

    dict_tag = sorted(dict_tag.items(), key=lambda x: x[1], reverse=True)
    print(dict_tag[:5])

    for key, v in dict_tag[:20]:
        print(key)
Example #8
0
                        },
                        "then": "$sentiment.confidence_scores.neutral"
                    }],
                    "default": {
                        "$max": [
                            "$sentiment.confidence_scores.positive",
                            "$sentiment.confidence_scores.negative",
                            "$sentiment.confidence_scores.neutral"
                        ]
                    }
                }
            }
        }  #project
    }]

    ts_sentiment = db.getInstance().get_tweet_collection().aggregate(pipeline)

    # use set() to remove the duplication
    set_tweet_sent = set()

    for row in ts_sentiment:
        set_tweet_sent.add((row['date'], row['sentiment'], row['score']))

    list_date = []
    list_sent_pos = []
    list_sent_neg = []
    list_sent_neu = []

    for date, sent, score in set_tweet_sent:
        if sent == 'mixed':
            continue