-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (23 loc) · 957 Bytes
/
app.py
File metadata and controls
27 lines (23 loc) · 957 Bytes
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
from tweepy import API, OAuthHandler
from textblob import TextBlob
from API_KEYS import api_key, api_secret_key
def clean_tweets(tweet):
tweet_words = str(tweet).split(' ')
clean_words = [word for word in tweet_words if not word.startswith('#')]
return ' '.join(clean_words)
def analyze(Topic):
positive_tweets, negative_tweets = [], []
authentication = OAuthHandler(api_key, api_secret_key)
api = API(authentication)
public_tweets = api.search(Topic, count=10)
cleaned_tweets = [clean_tweets(tweet.text) for tweet in public_tweets]
for tweet in cleaned_tweets:
tweet_polarity = TextBlob(tweet).sentiment.polarity
if tweet_polarity<0:
negative_tweets.append(tweet)
continue
positive_tweets.append(tweet)
return positive_tweets, negative_tweets
positive, negative = analyze('Magufuli')
print(positive , '\n\n', negative)
print(len(positive), ' VS ', len(negative))