mirror of
https://github.com/bellingcat/snscrape.git
synced 2026-06-12 12:28:28 +03:00
Fix crash on communities without a description
This commit is contained in:
@@ -517,7 +517,6 @@ class UserRef:
|
|||||||
class Community(snscrape.base.Item):
|
class Community(snscrape.base.Item):
|
||||||
id: int
|
id: int
|
||||||
name: str
|
name: str
|
||||||
description: str
|
|
||||||
created: datetime.datetime
|
created: datetime.datetime
|
||||||
admin: typing.Union[User, UserRef]
|
admin: typing.Union[User, UserRef]
|
||||||
creator: typing.Union[User, UserRef]
|
creator: typing.Union[User, UserRef]
|
||||||
@@ -527,6 +526,7 @@ class Community(snscrape.base.Item):
|
|||||||
rules: typing.List[str]
|
rules: typing.List[str]
|
||||||
theme: str
|
theme: str
|
||||||
bannerUrl: str
|
bannerUrl: str
|
||||||
|
description: typing.Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
@@ -2016,10 +2016,12 @@ class TwitterCommunityScraper(_TwitterAPIScraper):
|
|||||||
_logger.warning('Empty response or unavailable community')
|
_logger.warning('Empty response or unavailable community')
|
||||||
return None
|
return None
|
||||||
community = obj['data']['communityResults']['result']
|
community = obj['data']['communityResults']['result']
|
||||||
|
optKwargs = {}
|
||||||
|
if 'description' in community:
|
||||||
|
optKwargs['description'] = community['description']
|
||||||
return Community(
|
return Community(
|
||||||
id = int(community['id_str']),
|
id = int(community['id_str']),
|
||||||
name = community['name'],
|
name = community['name'],
|
||||||
description = community['description'],
|
|
||||||
created = datetime.datetime.fromtimestamp(community['created_at'] / 1000, tz = datetime.timezone.utc),
|
created = datetime.datetime.fromtimestamp(community['created_at'] / 1000, tz = datetime.timezone.utc),
|
||||||
admin = self._graphql_user_results_to_user(community['admin_results']),
|
admin = self._graphql_user_results_to_user(community['admin_results']),
|
||||||
creator = self._graphql_user_results_to_user(community['creator_results']),
|
creator = self._graphql_user_results_to_user(community['creator_results']),
|
||||||
@@ -2029,6 +2031,7 @@ class TwitterCommunityScraper(_TwitterAPIScraper):
|
|||||||
rules = [r['name'] for r in community['rules']],
|
rules = [r['name'] for r in community['rules']],
|
||||||
theme = community.get('custom_theme', community['default_theme']),
|
theme = community.get('custom_theme', community['default_theme']),
|
||||||
bannerUrl = community.get('custom_banner_media', community['default_banner_media'])['media_info']['original_img_url'],
|
bannerUrl = community.get('custom_banner_media', community['default_banner_media'])['media_info']['original_img_url'],
|
||||||
|
**optKwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_items(self):
|
def get_items(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user