зеркало из
https://github.com/viginum-datalab/twscrape.git
synced 2025-10-29 21:16:25 +02:00
feat: add profile urls to user model
Этот коммит содержится в:
родитель
aa4fbc8cad
Коммит
3654a053da
@ -104,6 +104,13 @@ def check_user(doc: User):
|
||||
assert doc.id == int(doc.id_str)
|
||||
|
||||
assert doc.username is not None
|
||||
assert doc.descriptionLinks is not None
|
||||
|
||||
if len(doc.descriptionLinks) > 0:
|
||||
for x in doc.descriptionLinks:
|
||||
assert x.url is not None
|
||||
assert x.text is not None
|
||||
assert x.tcourl is not None
|
||||
|
||||
obj = doc.dict()
|
||||
assert doc.id == obj["id"]
|
||||
|
||||
@ -104,15 +104,18 @@ class User(JSONTrait):
|
||||
profileBannerUrl: str | None = None
|
||||
protected: bool | None = None
|
||||
verified: bool | None = None
|
||||
descriptionLinks: list[TextLink] = field(default_factory=list)
|
||||
_type: str = "snscrape.modules.twitter.User"
|
||||
|
||||
# todo:
|
||||
# descriptionLinks: typing.Optional[typing.List[TextLink]] = None
|
||||
# link: typing.Optional[TextLink] = None
|
||||
# label: typing.Optional["UserLabel"] = None
|
||||
|
||||
@staticmethod
|
||||
def parse(obj: dict):
|
||||
links = get_or(obj, "entities.description.urls", []) + get_or(obj, "entities.url.urls", [])
|
||||
links = [TextLink.parse(x) for x in links]
|
||||
|
||||
return User(
|
||||
id=int(obj["id_str"]),
|
||||
id_str=obj["id_str"],
|
||||
@ -132,6 +135,7 @@ class User(JSONTrait):
|
||||
profileBannerUrl=obj.get("profile_banner_url"),
|
||||
verified=obj.get("verified"),
|
||||
protected=obj.get("protected"),
|
||||
descriptionLinks=links,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Загрузка…
x
Ссылка в новой задаче
Block a user