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 pie chart (using matplotlib) #30

Open
wants to merge 2 commits 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
26 changes: 20 additions & 6 deletions jobtweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import tweepy
from tweepy import OAuthHandler
from textblob import TextBlob
import matplotlib.pyplot as plt

class TwitterClient(object):
'''
Expand All @@ -11,13 +12,13 @@ def __init__(self):
'''
Class constructor or initialization method.
'''

consumer_key = 'XXXXXXXXXXXX'
consumer_secret = 'XXXXXXXXXXXX'
access_token = 'XXXXXXXXXXXX'
access_token_secret = 'XXXXXXXXXXXX'


try:

self.auth = OAuthHandler(consumer_key, consumer_secret)
Expand Down Expand Up @@ -54,9 +55,9 @@ def get_tweets(self, query, count = 10):
'''
Main function to fetch tweets and parse them.
'''

tweets = []

try:

fetched_tweets = self.api.search(q = query, count = count)
Expand Down Expand Up @@ -104,7 +105,20 @@ def main():
print("\n\nNegative tweets:")
for tweet in ntweets[:10]:
print(tweet['text'])

#After displaying percentages in the console -> show as pie-plot
percentages=[]
percentages.append(100*len(ptweets)/len(tweets))
percentages.append(100*len(ntweets)/len(tweets))
percentages.append(100*len(tweets)/len(tweets))
explode = (0, 0, 0) #change explodes to highlight a piece
labels=["Positve Tweets", "Negative Tweets", "Neutral Tweets"]
plt.pie(percentages,explode=explode,labels=labels,autopct='%1.1f%%')
plt.title("Graphical representation of the results",fontsize=16)
plt.axis("equal")
plt.legend(loc='upper center',bbox_to_anchor=(0.5, 0),ncol=3,fancybox=True,shadow=True)
plt.show()


if __name__ == "__main__":

main()