mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-07-04 14:28:36 +03:00
Merge pull request #218 from NoeCampos22/Place_Data
Extract more information on Twitter places
This commit is contained in:
@@ -42,7 +42,7 @@ class Tweet(snscrape.base.Item):
|
|||||||
quotedTweet: typing.Optional['Tweet'] = None
|
quotedTweet: typing.Optional['Tweet'] = None
|
||||||
mentionedUsers: typing.Optional[typing.List['User']] = None
|
mentionedUsers: typing.Optional[typing.List['User']] = None
|
||||||
coordinates: typing.Optional['Coordinates'] = None
|
coordinates: typing.Optional['Coordinates'] = None
|
||||||
place: typing.Optional[str] = None
|
place: typing.Optional['Place'] = None
|
||||||
|
|
||||||
username = snscrape.base._DeprecatedProperty('username', lambda self: self.user.username, 'user.username')
|
username = snscrape.base._DeprecatedProperty('username', lambda self: self.user.username, 'user.username')
|
||||||
outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks')
|
outlinksss = snscrape.base._DeprecatedProperty('outlinksss', lambda self: ' '.join(self.outlinks), 'outlinks')
|
||||||
@@ -99,6 +99,15 @@ class Coordinates:
|
|||||||
latitude: float
|
latitude: float
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass
|
||||||
|
class Place:
|
||||||
|
fullName: str
|
||||||
|
name: str
|
||||||
|
type: str
|
||||||
|
country: str
|
||||||
|
countryCode: str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class User(snscrape.base.Entity):
|
class User(snscrape.base.Entity):
|
||||||
# Most fields can be None if they're not known.
|
# Most fields can be None if they're not known.
|
||||||
@@ -378,7 +387,7 @@ class TwitterAPIScraper(snscrape.base.Scraper):
|
|||||||
if (coords := tweet['geo']['coordinates']) and len(coords) == 2:
|
if (coords := tweet['geo']['coordinates']) and len(coords) == 2:
|
||||||
kwargs['coordinates'] = Coordinates(coords[1], coords[0])
|
kwargs['coordinates'] = Coordinates(coords[1], coords[0])
|
||||||
if tweet.get('place'):
|
if tweet.get('place'):
|
||||||
kwargs['place'] = tweet['place']['full_name']
|
kwargs['place'] = Place(tweet['place']['full_name'], tweet['place']['name'], tweet['place']['place_type'], tweet['place']['country'], 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:
|
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"
|
# Take the first (longitude, latitude) couple of the "place square"
|
||||||
kwargs['coordinates'] = Coordinates(coords[0][0][0], coords[0][0][1])
|
kwargs['coordinates'] = Coordinates(coords[0][0][0], coords[0][0][1])
|
||||||
|
|||||||
Reference in New Issue
Block a user