位置过滤器 tweepy 模块

Location filter tweepy module

您好,我正在尝试只接收来自巴西的推文。这是我的代码,但我想知道是否有办法让位置更紧凑,以便不包括邻国(即该区域具有其他形状而不是正方形)。

class CustomStreamListener(tweepy.StreamListener):
    def on_data(self, data):
        try:
            with open('brasil.json', 'a') as f:
                f.write(data)
                return True
    except BaseException as e:
        print("Error on_data: %s" % str(e))
    return True

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(locations=[-74.1,-34.3,-34.1,5.6])

我解决了。答案可以在这里找到:https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters.html