我给我的代码,如下面的MWE
,它工作得很好.
import tweepy
BEARER = "my-bearer-token"
class MyListener(tweepy.StreamingClient):
def on_data(self, data):
try:
with open('python.json', 'a') as f:
f.write(str(data))
print(data)
return True
except BaseException as e:
print("Error on_data: %s" % str(e))
def on_connect(self):
print('Connected..!')
def on_error(self, status):
print(status)
return True
我定义了以下规则来获取特定于位置的数据:
stream = MyListener(BEARER)
stream.add_rules(tweepy.StreamRule('place:Lagos OR place:Abuja has:geo'))
stream.filter()
并成功检索到以下数据(来自print(data)
语句):
$ python tweetify.py
Connected..!
b'{"data":{"id":"1559694255035138048","text":"@halimahthebird N*gga the next day "},"matching_rules":[{"id":"1559694230766895104","tag":""}]}'
b'{"data":{"id":"1559694261976764421","text":"@O_luwatomiwa Mental illness I tell you \xf0\x9f\x98\x82"},"matching_rules":[{"id":"1559694230766895104","tag":""}]}'
b'{"data":{"id":"1559694339709730816","text":"@elonmusk He gon buy united at the dip"},"matching_rules":[{"id":"1559694230766895104","tag":""}]}'
...
很好,过滤器起作用了,这些推文来自规则中定义的位置.
*Question
但我想要的是位置坐标[LONG, LAT]
,而不是推文.我添加了运算符has:geo
,但不确定如何检索坐标.