-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreaming.py
44 lines (30 loc) · 1.08 KB
/
Streaming.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
## Autor: Allan Sesto - 02/04/18
import tweepy
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
### Tokens e Chaves de autenticação
consumer_key = 'post_your_key_here'
consumer_secret = 'post_your_secret_here'
access_token = 'post_your_token_here'
access_secret = 'post_your_secretToken_here'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
### Declere da API com as palavras chaves
api = tweepy.API(auth)
class MyListener(StreamListener):
def on_data(self, data):
try:
with open('Analysis_hoje.json', 'a') as f:
f.write(data)
return True
except BaseException as e:
print("Error on_data: %s" % str(e))
return True
def on_error(self, status):
print(status)
return True
## Hashs de Buscas
twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(
track=['Terça', 'Terça-Feira', 'Lula', 'Aecio Neves', 'Politica', 'Lava-Jato', 'Policia Federal', 'O Mecanismo'])