Tweepy filtro não está funcionando
Pergunta
Existe uma função no Tweepy se você só quer ver os tweets selecionados a partir de twitter de identificação.
streaming_api.filter(follow=("501088042","107536557",), track=Q)
infelizmente não está a funcionar (altamente duvidoso) ou eu estou fazendo algo de errado.Se eu definir follow=None
as funções de script perfeitamente.Quando eu definir o ID de utilizador continua a funcionar como se eu já não mudou nada.Como faço para filtrar a minha fluxo de usar somente o ID que eu definida em follow
?
Este é o código:
import sys
import tweepy
import webbrowser
import MySQLdb
Q = sys.argv[1:]
db = MySQLdb.connect("localhost","user","password","db" )
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
cur = db.cursor()
class CustomStreamListener(tweepy.StreamListener):
def on_status(self, status):
try:
print "%s\t%s\t%s\t%s" % (status.text,
status.author.screen_name,
status.created_at,
status.source,)
cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)", (status.text,
status.author.screen_name,
status.created_at,
status.source))
except Exception, e:
print >> sys.stderr, 'Encountered Exception:', e
pass
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
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60)
print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' '.join(sys.argv[1:]),)
streaming_api.filter(follow=("501088042","107536557",), track=Q)
Solução
Fixa-lo!
streaming_api.filter(follow=['501088042'], track=Q)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow