"Stackoverflow" yazan tweets'i başarıyla toplayan bir çalışma komut dosyası var. Ancak, betiği iPython'da çalıştırmak istiyorum (ayrı bir .py dosyası yürütmek yerine). İdeal olarak, sadece ipyb dosyasını açmak istiyorum, tümünü çalıştır'ı seçin ve bir hafta kadar çalışmasına izin verin (tabii ki dizüstü bilgisayarımı kapatmayın) ve sonuçta bir haftalık bir tweet değerine sahip bir .json dosyasına sahibim.Tweepy bir Twitter akışını bir dosyaya nasıl kaydederim?
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
access_token = "x"
access_token_secret = "x"
consumer_key = "x"
consumer_secret = "x"
# file name that you want to open is the second argument
save_file = open('data.json', 'a')
class listener(StreamListener):
def on_data(self, data):
print(data)
return True
def on_error(self, status):
print(status)
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["stackoverflow"])