0
選択したツイッターIDのツイートのみを表示したい場合は、Tweepyに機能があります。トゥイーピーフィルターが機能していない
streaming_api.filter(follow=("501088042","107536557",), track=Q)
残念ながら、それは機能していない(非常に疑わしい)か、私は何か間違っています。私がfollow=None
と設定すると、スクリプトは完全に機能します。ユーザーIDを設定すると、何も変更しなかったかのように動作し続けます。 follow
に設定したIDだけを使用するようにストリームをフィルタリングするにはどうすればよいですか?
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)