-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
31 lines (27 loc) · 973 Bytes
/
driver.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
import sys
from re import sub
from textblob import TextBlob
from authentication import auth
from getTweets import fetch_tweets
from final_hit import get_Final
def driver(str):
try:
api_obj, usrName = auth()
print("Logged in as:", usrName)
except ValueError:
print("Invalid keys or tokens.\nAuthentication Failed!!\n")
print("Please checkout \"README.md\" and \"authentication.py\" file.")
sys.exit()
twat = []
srch, tweets = fetch_tweets(api_obj,str)
for strippin in tweets:
texts = strippin.text
anal_text = ' '.join(sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])| (\w+: / / \S+)", " ", texts).split())
bob = TextBlob(anal_text)
textiment = {'tweet': texts, 'sentiment': bob.sentiment.polarity}
if strippin.retweet_count:
twat.append(textiment)
else:
if textiment not in tweets:
twat.append(textiment)
get_Final(twat, srch)