From e7df2069a12702ce68ae86938b08965694331344 Mon Sep 17 00:00:00 2001 From: Akarsh Shukla Date: Fri, 8 Oct 2021 00:48:08 +0530 Subject: [PATCH 1/2] For issue #3 --- jobtweets.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/jobtweets.py b/jobtweets.py index 02793e7..e90909e 100644 --- a/jobtweets.py +++ b/jobtweets.py @@ -56,29 +56,25 @@ def get_tweets(self, query, count = 10): ''' tweets = [] - + querl=query.split() + try: - - fetched_tweets = self.api.search(q = query, count = count) - - - for tweet in fetched_tweets: - - parsed_tweet = {} + for qu in querl: + fetched_tweets = self.api.search(q = qu.strip(), count = count) + for tweet in fetched_tweets: + parsed_tweet = {} + parsed_tweet['text'] = tweet.text - parsed_tweet['text'] = tweet.text - - parsed_tweet['sentiment'] = self.get_tweet_sentiment(tweet.text) + parsed_tweet['sentiment'] = self.get_tweet_sentiment(tweet.text) - if tweet.retweet_count > 0: + if tweet.retweet_count > 0: - if parsed_tweet not in tweets: + if parsed_tweet not in tweets: + tweets.append(parsed_tweet) + else: tweets.append(parsed_tweet) - else: - tweets.append(parsed_tweet) - return tweets except tweepy.TweepError as e: From 7c646cdab62feb14efca2b5ac2eb90a41c8261d8 Mon Sep 17 00:00:00 2001 From: Akarsh Shukla Date: Sat, 9 Oct 2021 01:09:35 +0530 Subject: [PATCH 2/2] Pie Chart issue --- jobtweets.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jobtweets.py b/jobtweets.py index e90909e..72d8066 100644 --- a/jobtweets.py +++ b/jobtweets.py @@ -2,7 +2,8 @@ import tweepy from tweepy import OAuthHandler from textblob import TextBlob - +from matplotlib import pyplot as plt +import numpy as np class TwitterClient(object): ''' Generic Twitter Class for sentiment analysis. @@ -92,7 +93,11 @@ def main(): print("Negative tweets percentage: {} %".format(100*len(ntweets)/len(tweets))) print("Neutral tweets percentage: {} % ".format(100*(len(tweets) - len(ntweets) - len(ptweets))/len(tweets))) - + data=[100*len(ptweets)/len(tweets),100*len(ntweets)/len(tweets),100*(len(tweets) - len(ntweets) - len(ptweets))/len(tweets)] + lab=['Positive','Negative','Neutral'] + fig = plt.figure(figsize =(10, 7)) + plt.pie(data, labels = lab) + plt.show() print("\n\nPositive tweets:") for tweet in ptweets[:10]: print(tweet['text'])