研究プロジェクトのためにツイートを追跡して mongodb に保存できるアプリを開発する必要があります (お察しのとおり、私は初心者なので、ご容赦ください)。ターミナル ウィンドウを介してツイート ストリーミングを送信する次のコードを見つけました。
import sys
import tweepy
consumer_key=""
consumer_secret=""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
print status.text
def on_error(self, status_code):
print >> sys.stderr, 'Encountered error with status code:', status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(track=['Gandolfini'])
このコードを変更して、つぶやきを画面上にストリーミングする代わりに、mongodb データベースに送信する方法はありますか?
ありがとう