Esempio n. 1
0
# Retrieving tweets by hashtag.
dico_tweet = []
texte = []

for tweet in tweepy.Cursor(api.search, q="#XboxSeriesS", lang="fr").items(10):
    if tweet.retweeted == False:
        temp = {}
        tempSentiment = {}
        tempConfidence = {}
        temp['ID'] = tweet.id
        temp['Texte'] = tweet.text
        temp['Date'] = tweet.created_at.strftime("%Y-%d-%m")
        temp['Auteur'] = tweet.user.screen_name
        texte.append(tweet.text)
        response = client.analyze_sentiment(texte)
        tempSentiment['Sentiment Score'] = response[0].sentiment
        temp['Sentiment'] = tempSentiment
        tempConfidence['Score Positif'] = response[
            0].confidence_scores.positive
        tempConfidence['Score Neutre'] = response[0].confidence_scores.neutral
        tempConfidence['Score Negatif'] = response[
            0].confidence_scores.negative
        temp['Confidence Scores'] = tempConfidence
        dico_tweet.append(temp)

# Display of dictionary content and tweets identifiers.
# pprint("contenu : " + str(dico_tweet))
# for i in collection_xbox_tweet.find():
#     for j in dico_tweet:
#         # print("collection_xbox_tweet : " + str(i["ID"]) + "    dico_tweet : " + str(j["ID"]))