如何使用框边界矩形从国家/地区流式传输推文? 我有代码按位置流,但我想做一个循环,说:对于每条推文,看看这条推文是在矩形1或矩形2或矩形(n)中,否则不要接受这条推文。
我的代码是:
import sys
import tweepy
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret=''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
class CustomStreamListener(tweepy.StreamListener):
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
sapi.filter(locations=[1.9,34.7,7.94,36.63])
在这段代码中,我过滤了一个矩形,但我想要一个像这样的代码:
For each tweet t_i:
For each rectangle r_j:
If tweet_is_in_rectangle(r_j) == False:
exclude t_i