I give my code as in the below MWE
which works fine.
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
And I define the following rules to get location specific data:
stream = MyListener(BEARER)
stream.add_rules(tweepy.StreamRule('place:Lagos OR place:Abuja has:geo'))
stream.filter()
And successfully retrieved the following data (from print(data)
statement):
$ 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":""}]}'
...
Good that the filter works, those tweets came from the defined place in rule.
*Question
But I want to retrieve the location coordinates [LONG, LAT]
not the tweets. I added the operator has:geo
but not sure how to retrieve the coordinates.