mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-06-08 02:28:29 +03:00
Get more data from the place
Data like the country, place type and the single place name are now also returned on the JSON.
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user