Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the coordinates from Tweepy?

I have the following code for retrieving tweets. The geocode specified is an area within New York State. However, when I print the location using print(json_reply['user']['location']), it is printing the location as Voorburg, Netherlands. I guess this is the location specified by user in the profile information. Also, geocode is always returning null. I am interested in Tweets from New York state alongwith the co-ordinates.

tweets = api.search(q='xyz', lang='en', since='2016-11-02',until='2016-11-06', geocode='43,-75,90km', count=1)

json_str = json.dumps(tweets[0]._json)
print(json_str)
json_reply = json.loads(json_str)
print(json_reply['text'])
print(json_reply['created_at'])
print(json_reply['user']['location'])
print(json_reply['geo'])

Voorburg, Netherlands

like image 329
sheetal_158 Avatar asked Oct 30 '22 17:10

sheetal_158


1 Answers

You can actually do this with tweepy's search API.

First get the place_id via...

>>> places = api.geo_search(lat='43', long='-75', max_results=10)
>>> places[0].id
u'23e921b82040ccd6'

Then use tweepy's search API with the place:<place_id>.

tweets = api.search(q='place:23e921b82040ccd6', count=100)

See: https://dev.twitter.com/rest/public/search-by-place

like image 98
Thomas Schultz Avatar answered Dec 10 '22 06:12

Thomas Schultz