Reputation:
I'm using Tweepy to pull the coordinates of a tweet. It looks like this after using json to load it.
tweet = json.loads(data)
print(tweet['coordinates'])
{'coordinates': [-86.771035, 39.514024], 'type': 'Point'}
I want to store the longitude and latitude into a database, how would I directly access the coordinates? I tried using tweet['coordinates'][0] and various variations but it doesn't seem to be working the way I want.
Upvotes: 0
Views: 2721
Reputation: 2144
You can get coordinates data in the following way:
for tweet in tweepy.Cursor(api.search,q='love',count = num_tweets).items():
if (tweet.coordinates is not None):
lon = tweet.coordinates['coordinates'][0]
lat = tweet.coordinates['coordinates'][1]
It is strange, but I had to try many forms and ways to make it work.
Upvotes: 2
Reputation: 1410
Try:
latitude, longitude = tweet["coordinates"]["coordinates"]
Because tweet["coordinates"] returns other dictionary that has a key also called "coordinates" with a list as its value.
Upvotes: -1