From 39a34a57ac198914b764a62a354956181e03ff09 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Tue, 13 Apr 2021 20:15:42 +0000 Subject: [PATCH] Handle API endpoints that don't include geolocation data (e.g. twitter-profile scraper) Fixes #215 --- snscrape/modules/twitter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snscrape/modules/twitter.py b/snscrape/modules/twitter.py index 9875714..ddac147 100644 --- a/snscrape/modules/twitter.py +++ b/snscrape/modules/twitter.py @@ -369,15 +369,15 @@ class TwitterAPIScraper(snscrape.base.Scraper): ] if 'user_mentions' in tweet['entities'] and tweet['entities']['user_mentions'] else None # https://developer.twitter.com/en/docs/tutorials/filtering-tweets-by-location - if tweet['coordinates']: + if tweet.get('coordinates'): # coordinates root key (if present) presents coordinates in the form [LONGITUDE, LATITUDE] if (coords := tweet['coordinates']['coordinates']) and len(coords) == 2: kwargs['coordinates'] = Coordinates(coords[0], coords[1]) - elif tweet['geo']: + elif tweet.get('geo'): # coordinates root key (if present) presents coordinates in the form [LATITUDE, LONGITUDE] if (coords := tweet['geo']['coordinates']) and len(coords) == 2: kwargs['coordinates'] = Coordinates(coords[1], coords[0]) - if tweet['place']: + if tweet.get('place'): kwargs['place'] = tweet['place']['full_name'] if 'coordinates' not in kwargs and tweet['place']['bounding_box'] and (coords := tweet['place']['bounding_box']['coordinates']) and coords[0] and len(coords[0][0]) == 2: # Take the first (longitude, latitude) couple of the "place square"