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
| from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
from json import *
cle = 'NorVSuR1eh0xdzkex4Y4mA'
clesecrete = 'F0AbGFdmMrwNhDKYGKzEQrqXTMEViKWbu9tI5jYkb0'
jeton = '2234554214-sBqwoOCCEBVRktuCBeVdaWmcVhu6dluUfLSbecq'
jetonsecret = 'KaagCeViNedcHrSctsGoXNHq0nWTZpV6E4t6x4ddXrYzL'
class listener(StreamListener):
def on_data(self,data):
try:
print data
saveFile=open('twitter_ronaldo.json','a')
saveFile.write(data)
saveFile.write('\n')
saveFile.close()
return True
except BaseException, e:
print 'Erreur extraction,',str(e)
time.sleep(5)
def on_error(self, status):
print status
auth = OAuthHandler(cle, clesecrete)
auth.set_access_token(jeton, jetonsecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["ronaldo"]) |
Partager