· 7 years ago · Mar 26, 2018, 12:16 AM
1import tweepy
2import json
3
4APP_KEY = 'lSNLVGp1o2Ey5xOaEnM26mAtw' # Customer Key here
5APP_SECRET = 'Cxe0ki8mHKl615e7sQBJhtoGl68WA2Q8qjm2MI7wZyebH1WNBZ' # Customer secret here
6OAUTH_TOKEN = '978050823828762624-ONKYDUkIuI5UPExDVmalI8Jh4cicYIx' # Access Token here
7OAUTH_TOKEN_SECRET = 'nhskXpnNgEXsEErIob9YoW8CZJwe5BkV74ZR7N5cmmOxQ' # Access Token Secret here
8
9auth = tweepy.OAuthHandler(APP_KEY, APP_SECRET)
10auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
11
12class MyListener(tweepy.StreamListener):
13
14 def on_data(self, data):
15 try:
16 with open('blood.json', 'a') as f:
17 f.write(data)
18 return True
19 except BaseException as e:
20 print("Error on_data: %s" % str(e))
21 return True
22
23 def on_error(self, status):
24 print(status)
25 return True
26
27twitter_stream = tweepy.Stream(auth, MyListener())
28twitter_stream.filter(track=['doacao de sangue', 'blood donation'])