Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Matplotlib and formed the pie chart #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions jobtweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import tweepy
from tweepy import OAuthHandler
from textblob import TextBlob
import matplotlib.pyplot as plt


class TwitterClient(object):
'''
Expand Down Expand Up @@ -83,7 +85,16 @@ def get_tweets(self, query, count = 10):

except tweepy.TweepError as e:
print("Error : " + str(e))


def plotPieChart(negativeTweetercentage, positiveTweetPercentage, neutralTweetPercentage):
labels = 'Negative Tweets', 'Positive Tweets', 'Neutral Tweets'
sizes = [negativeTweetercentage, positiveTweetPercentage, neutralTweetPercentage]
explode = (0, 0, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()

def main():
api = TwitterClient()
tweets = api.get_tweets(query = 'Job Opportunities', count = 500)
Expand All @@ -96,7 +107,7 @@ 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)))

plotPieChart(100*len(ptweets)/len(tweets),100*len(ptweets)/len(tweets),100*(len(tweets) - len(ntweets) - len(ptweets))/len(tweets))
print("\n\nPositive tweets:")
for tweet in ptweets[:10]:
print(tweet['text'])
Expand Down