J'ai besoin de suivre de nombreux mots clés sur twitter et d'envoyer les tweets à MongoDB. Je pour mon code:Suivi du filtre (tweepy) capturé un tweet
How can I consume tweets from Twitter's streaming api and store them in mongodb
import json
import pymongo
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 __init__(self, api):
self.api = api
super(tweepy.StreamListener, self).__init__()
self.db = pymongo.MongoClient().test
def on_data(self, tweet):
self.db.tweets.insert(json.loads(tweet))
def on_error(self, status_code):
return True # Don't kill the stream
def on_timeout(self):
return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener(api))
to_track = ['keyword1', 'keyword2', 'keyword3']
sapi.filter(track = to_track)
est-il un moyen pour moi de garder une trace des mots clés est responsable de chaque tweet entrant? (Sans faire une recherche grep dans chacun)
Up up up up up up up –