add pinned tweets info to user profile #201

Этот коммит содержится в:
Vlad Pronsky 2024-06-29 22:13:11 +03:00
родитель fe18dd1e17
Коммит 664114e8bc
3 изменённых файлов: 11 добавлений и 1 удалений

Просмотреть файл

@ -132,6 +132,10 @@ def check_user(doc: User):
assert doc.username is not None
assert doc.descriptionLinks is not None
assert doc.pinnedIds is not None
if doc.pinnedIds:
for x in doc.pinnedIds:
assert isinstance(x, int)
if len(doc.descriptionLinks) > 0:
for x in doc.descriptionLinks:
@ -311,8 +315,12 @@ async def test_user_tweets():
tweets = await gather(api.user_tweets(2244994945))
assert len(tweets) > 0
is_any_pinned = False
for doc in tweets:
check_tweet(doc)
is_any_pinned = is_any_pinned or doc.id in doc.user.pinnedIds
assert is_any_pinned, "at least one tweet should be pinned (or bad luck with data)"
async def test_user_tweets_and_replies():

Просмотреть файл

@ -123,6 +123,7 @@ class User(JSONTrait):
blue: bool | None = None
blueType: str | None = None
descriptionLinks: list[TextLink] = field(default_factory=list)
pinnedIds: list[int] = field(default_factory=list)
_type: str = "snscrape.modules.twitter.User"
# todo:
@ -153,6 +154,7 @@ class User(JSONTrait):
blueType=obj.get("verified_type"),
protected=obj.get("protected"),
descriptionLinks=_parse_links(obj, ["entities.description.urls", "entities.url.urls"]),
pinnedIds=[int(x) for x in obj.get("pinned_tweet_ids_str", [])],
)

Просмотреть файл

@ -237,7 +237,7 @@ class QueueClient:
msg = [
"Unknown error. Account timeouted for 15 minutes.",
"Create issue please: https://github.com/vladkens/twscrape/issues",
f"If it mistake, you can unlock account now with `twscrape reset_locks`. Err: {type(e)}: {e}",
f"If it mistake, you can unlock accounts with `twscrape reset_locks`. Err: {type(e)}: {e}",
]
logger.warning(" ".join(msg))