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

For issue #3 #50

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
37 changes: 19 additions & 18 deletions jobtweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -56,29 +57,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:
Expand All @@ -96,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'])
Expand Down