-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitter_senti.py
More file actions
71 lines (42 loc) · 1.54 KB
/
twitter_senti.py
File metadata and controls
71 lines (42 loc) · 1.54 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
Created on Fri May 26 19:59:01 2017
@author: Harsha SlimShady
"""
import tweepy
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
import json
from textblob import TextBlob
import re
consumer_key = 'C5AuTRgdv5NNtRtIcvlsbiUT3'
consumer_secret = 'WI1ePKnfXNPcX6FoBhWUoqkT4rJn55oA5eIHVSCxJWhYphd1MI'
acess_token = '3022120112-WfskTNLDV2RZSKyvimx4DFX0reOWcDRFGADakYr'
acess_secret = 'ICW6OPMkirNur8m9x1zhdwpx8uBCMW0SouL5aLxKxnVCK'
auth = OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(acess_token,acess_secret)
api = tweepy.API(auth)
class listener(StreamListener):
def on_data(self,tweet):
type(tweet)
def on_error(self,status):
print(status)
def getOwnTimeline():
for tweet in api.home_timeline():
blob = TextBlob(clean_tweet(tweet.text))
if blob.sentiment.polarity > 0:
print('positive one by ' + tweet.user.name)
else:
print('Negetive one by ' + tweet.user.name)
def getUser(name):
user = api.get_user(name)
print(user.screen_name)
print(user.followers_count)
for user in user.friends():
print(user.screen_name)
def clean_tweet(tweet):
tweet=" ".join(re.findall("[a-zA-Z]+", tweet))
return tweet
twitterStream = Stream(auth,listener())
twitterStream.filter(track = ["python"])