简体   繁体   English

TwythonStreamer:OR不能用作过滤器

[英]TwythonStreamer: OR does not work as a filter

I'm not sure why the following code does not return any result. 我不确定以下代码为什么不返回任何结果。 If I put streamer.statuses.filter(track = 'data') , then it outputs tweets. 如果我放置streamer.statuses.filter(track = 'data') ,那么它将输出tweets。 However, if I use join with OR , it does not work, though I am using 'data' as one of options. 但是,如果我将joinOR使用,则不会起作用,尽管我将'data'用作选项之一。 Finally, if I use track=keywords , it neither works. 最后,如果我使用track=keywords ,那么它们都不起作用。

from twython import TwythonStreamer
from collections import Counter

tweets = []

class TweetStreamer(TwythonStreamer):
    def on_success(self, data):
        if 'text' in data:
            tweets.append(data['text'].encode('utf-8'))
            print data['text'].encode('utf-8')
        if len(tweets)>10:
            self.disconnect()

    def on_error(self, status_code, data):
        print status_code
        self.disconnect()

CONSUMER_KEY = "..."
CONSUMER_SECRET = "..."
ACCESS_TOKEN = "..."
ACCESS_TOKEN_SECRET = "..."

streamer = TweetStreamer(CONSUMER_KEY, CONSUMER_SECRET,
                         ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

keywords = ['data','information']
track = " OR ".join(keywords)

streamer.statuses.filter(track = track)

You have to use the Twitter API in a correct way. 您必须以正确的方式使用Twitter API。

From the doc : 文档

  • For logical AND separate with space: "data information" == " ".join(['data', 'information']) 对于逻辑AND,并用空格分隔: "data information" == " ".join(['data', 'information'])
  • For logical OR separate with comma: "data,information" == ",".join(['data', 'information']) 对于逻辑或以逗号分隔: "data,information" == ",".join(['data', 'information'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM