From dbf2a2f6893a9b6bef3e3f6ba503f00ae3e3cb5c Mon Sep 17 00:00:00 2001 From: NoeCampos22 Date: Mon, 19 Apr 2021 12:01:14 -0500 Subject: [PATCH] Get more data from the place Data like the country, place type and the single place name are now also returned on the JSON. --- snscrape/modules/twitter.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/snscrape/modules/twitter.py b/snscrape/modules/twitter.py index ddac147..900e16c 100644 --- a/snscrape/modules/twitter.py +++ b/snscrape/modules/twitter.py @@ -43,6 +43,10 @@ class Tweet(snscrape.base.Item): mentionedUsers: typing.Optional[typing.List['User']] = None coordinates: typing.Optional['Coordinates'] = None place: typing.Optional[str] = None + place_name: typing.Optional[str] = None + place_type: typing.Optional[str] = None + country: typing.Optional[str] = None + country_code: typing.Optional[str] = None username = snscrape.base._DeprecatedProperty('username', lambda self: self.user.username, 'user.username') outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks') @@ -378,7 +382,12 @@ class TwitterAPIScraper(snscrape.base.Scraper): if (coords := tweet['geo']['coordinates']) and len(coords) == 2: kwargs['coordinates'] = Coordinates(coords[1], coords[0]) if tweet.get('place'): + # get place data kwargs['place'] = tweet['place']['full_name'] + kwargs['place_name'] = tweet['place']['name'] + kwargs['place_type'] = tweet['place']['place_type'] + kwargs['country'] = tweet['place']['country'] + kwargs['country_code'] = tweet['place']['country_code'] 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" kwargs['coordinates'] = Coordinates(coords[0][0][0], coords[0][0][1])