-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (38 loc) · 1.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
from textblob import TextBlob
import matplotlib.pyplot as plt
from tweepy import OAuthHandler,API,Cursor
ck = 'costumer key'
cs = 'costumer secret key'
at = 'access token key'
ats = 'access token secret key'
auth = OAuthHandler(ck,cs)
auth.set_access_token(at,ats)
api = API(auth)
term = "Pakistan"
noterm = 1000
tweets = Cursor(api.search, q=term)
tweets = tweets.items(noterm)
positive = 0
negative = 0
neutral = 0
for t in tweets:
value = TextBlob(t.text)
if(value.sentiment.polarity==0):
neutral+=1
elif(value.sentiment.polarity>0):
positive+=1
elif (value.sentiment.polarity < 0):
negative += 1
neutral = (neutral/noterm)*100
positive = (positive/noterm)*100
negative = (negative/noterm)*100
labels = 'Positive', 'Negative', 'Neutral'
sizes = [positive, negative, neutral]
explode = (0.1, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal')
plt.title("Popularity graph of search term: "+term)
plt.show()