diff --git a/tests/test_parser.py b/tests/test_parser.py index 100ee45..dd3ee9f 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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(): diff --git a/twscrape/models.py b/twscrape/models.py index 2c8d612..2af8527 100644 --- a/twscrape/models.py +++ b/twscrape/models.py @@ -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 @@ def parse(obj: dict, res=None): 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", [])], ) diff --git a/twscrape/queue_client.py b/twscrape/queue_client.py index db73ab0..b7a4dec 100644 --- a/twscrape/queue_client.py +++ b/twscrape/queue_client.py @@ -237,7 +237,7 @@ async def req(self, method: str, url: str, params: ReqParams = None) -> Response 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))