-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter_analysis.py
More file actions
26 lines (21 loc) · 797 Bytes
/
twitter_analysis.py
File metadata and controls
26 lines (21 loc) · 797 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
#TWITTER SENTIMENT ANALYSIS USING PYTHON
#Import Libraries
import tweepy
from textblob import TextBlob
#Twitter Authentication
consumer_key = 'T4gcarK7j66B1RrWVBOr39rl4'
consumer_secret = 'xpBnInfYtdjqPXhQZeZMvJqCnt5S6FnY3HVYhPSBYaJ8cUAwjx'
access_token = '1212320988563558406-cevIttMGKByyeZThIq9ki7fguw7IKd'
access_token_secret = 'cpykrsZPLowsxzzrZob5zqaR7BEp4cCLgWCIsaMmmzNtL'
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token, access_token_secret)
#Reading data from twitter
api = tweepy.API(auth)
public_tweets = api.search('Donald Trump')
#Printing the data read from twitter
for tweet in public_tweets:
print(tweet.text)
#Performing Sentiment Analysis
analysis = TextBlob(tweet.text)
type(analysis)
print(analysis.sentiment)