-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweet SA.py
50 lines (41 loc) · 1.41 KB
/
Tweet SA.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
47
48
49
50
from textblob import TextBlob
import tweepy
import sys
mykeys = open('TextFileWithTwitterAPIKeys','r').read().splitlines()
api_key = mykeys[0]
api_key_secret = mykeys[1]
access_token = mykeys[2]
access_token_secret = mykeys[3]
auth_handler = tweepy.OAuthHandler(consumer_key=api_key,consumer_secret=api_key_secret)
auth_handler.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth_handler)
search_term = 'example'
tweet_amount = 200
tweets = tweepy.Cursor(api.search, q=search_term, lang='en').items(tweet_amount)
polarity = 0
positive = 0
neutral = 0
negative = 0
for tweet in tweets:
final_text = tweets.text.replace('RT','')
if final_text.startswith(' @'):
position = final_text.index(':')
final_text = final_text[position+2:]
if final_text.startswith('@'):
position = final_text.index(' ')
final_text = final_text[position+2:]
analysis = TextBlob(final_text)
tweet_polarity = analysis.polarity
if tweet_polarity > 0.00:
positive+=1
elif tweet_polarity < 0.00:
negative += 1
elif tweet_polarity == 0.00:
neutral += 1
polarity += tweet_polarity
print(polarity)
print(f'Amount of positive tweets: {positive}')
print(f'Amount of negative tweets: {negative}')
print(f'Amount of neutral tweets: {neutral}')
#find a way to limit region to Dominican Republic
#do it in spanish