зеркало из
https://github.com/viginum-datalab/twscrape.git
synced 2025-10-29 13:06:13 +02:00
add pinned tweets info to user profile #201
Этот коммит содержится в:
родитель
fe18dd1e17
Коммит
664114e8bc
@ -132,6 +132,10 @@ def check_user(doc: User):
|
|||||||
|
|
||||||
assert doc.username is not None
|
assert doc.username is not None
|
||||||
assert doc.descriptionLinks 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:
|
if len(doc.descriptionLinks) > 0:
|
||||||
for x in doc.descriptionLinks:
|
for x in doc.descriptionLinks:
|
||||||
@ -311,8 +315,12 @@ async def test_user_tweets():
|
|||||||
tweets = await gather(api.user_tweets(2244994945))
|
tweets = await gather(api.user_tweets(2244994945))
|
||||||
assert len(tweets) > 0
|
assert len(tweets) > 0
|
||||||
|
|
||||||
|
is_any_pinned = False
|
||||||
for doc in tweets:
|
for doc in tweets:
|
||||||
check_tweet(doc)
|
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():
|
async def test_user_tweets_and_replies():
|
||||||
|
|||||||
@ -123,6 +123,7 @@ class User(JSONTrait):
|
|||||||
blue: bool | None = None
|
blue: bool | None = None
|
||||||
blueType: str | None = None
|
blueType: str | None = None
|
||||||
descriptionLinks: list[TextLink] = field(default_factory=list)
|
descriptionLinks: list[TextLink] = field(default_factory=list)
|
||||||
|
pinnedIds: list[int] = field(default_factory=list)
|
||||||
_type: str = "snscrape.modules.twitter.User"
|
_type: str = "snscrape.modules.twitter.User"
|
||||||
|
|
||||||
# todo:
|
# todo:
|
||||||
@ -153,6 +154,7 @@ class User(JSONTrait):
|
|||||||
blueType=obj.get("verified_type"),
|
blueType=obj.get("verified_type"),
|
||||||
protected=obj.get("protected"),
|
protected=obj.get("protected"),
|
||||||
descriptionLinks=_parse_links(obj, ["entities.description.urls", "entities.url.urls"]),
|
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 = [
|
msg = [
|
||||||
"Unknown error. Account timeouted for 15 minutes.",
|
"Unknown error. Account timeouted for 15 minutes.",
|
||||||
"Create issue please: https://github.com/vladkens/twscrape/issues",
|
"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))
|
logger.warning(" ".join(msg))
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user