зеркало из
https://github.com/viginum-datalab/twscrape.git
synced 2025-10-29 13:06:13 +02:00
fix bookmarks
Этот коммит содержится в:
родитель
8acfe41bba
Коммит
54c79665a9
@ -1,17 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
import twscrape
|
||||
from twscrape.utils import gather
|
||||
|
||||
async def main():
|
||||
api = twscrape.API()
|
||||
# add accounts here or before from cli (see README.md for examples)
|
||||
await api.pool.add_account("BookmarkTe60140", "", '', '')
|
||||
await api.pool.login_all()
|
||||
bms = await gather(api.bookmarks())
|
||||
for bm in bms:
|
||||
print(bm.rawContent)
|
||||
print('-----')
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@ -121,7 +121,14 @@ class API:
|
||||
|
||||
obj = rep.json()
|
||||
els = get_by_path(obj, "entries") or []
|
||||
els = [x for x in els if not (x["entryId"].startswith("cursor-") or x["entryId"].startswith("messageprompt-"))]
|
||||
els = [
|
||||
x
|
||||
for x in els
|
||||
if not (
|
||||
x["entryId"].startswith("cursor-")
|
||||
or x["entryId"].startswith("messageprompt-")
|
||||
)
|
||||
]
|
||||
cur = self._get_cursor(obj, cursor_type)
|
||||
|
||||
rep, cnt, active = self._is_end(rep, queue, els, cur, cnt, limit)
|
||||
@ -386,30 +393,6 @@ class API:
|
||||
yield x
|
||||
|
||||
# user_media
|
||||
|
||||
async def bookmarks_raw(self, limit=-1, kv=None):
|
||||
op = OP_UserBookmarks
|
||||
kv = {
|
||||
"count": 20,
|
||||
"includePromotedContent": False,
|
||||
"withClientEventToken": False,
|
||||
"withBirdwatchNotes": False,
|
||||
"withVoice": True,
|
||||
"withV2Timeline": True,
|
||||
**(kv or {}),
|
||||
}
|
||||
ft = {
|
||||
'graphql_timeline_v2_bookmark_timeline': True,
|
||||
}
|
||||
async with aclosing(self._gql_items(op, kv, ft, limit=limit)) as gen:
|
||||
async for x in gen:
|
||||
yield x
|
||||
|
||||
async def bookmarks(self, limit=-1, kv=None):
|
||||
async with aclosing(self.bookmarks_raw(limit=limit, kv=kv)) as gen:
|
||||
async for rep in gen:
|
||||
for x in parse_tweets(rep.json(), limit):
|
||||
yield x
|
||||
|
||||
async def user_media_raw(self, uid: int, limit=-1, kv=None):
|
||||
op = OP_UserMedia
|
||||
@ -478,3 +461,29 @@ class API:
|
||||
async for rep in gen:
|
||||
for x in parse_tweets(rep.json(), limit):
|
||||
yield x
|
||||
|
||||
# Get current user bookmarks
|
||||
|
||||
async def bookmarks_raw(self, limit=-1, kv=None):
|
||||
op = OP_UserBookmarks
|
||||
kv = {
|
||||
"count": 20,
|
||||
"includePromotedContent": False,
|
||||
"withClientEventToken": False,
|
||||
"withBirdwatchNotes": False,
|
||||
"withVoice": True,
|
||||
"withV2Timeline": True,
|
||||
**(kv or {}),
|
||||
}
|
||||
ft = {
|
||||
"graphql_timeline_v2_bookmark_timeline": True,
|
||||
}
|
||||
async with aclosing(self._gql_items(op, kv, ft, limit=limit)) as gen:
|
||||
async for x in gen:
|
||||
yield x
|
||||
|
||||
async def bookmarks(self, limit=-1, kv=None):
|
||||
async with aclosing(self.bookmarks_raw(limit=limit, kv=kv)) as gen:
|
||||
async for rep in gen:
|
||||
for x in parse_tweets(rep.json(), limit):
|
||||
yield x
|
||||
|
||||
Загрузка…
x
Ссылка в новой задаче
Block a user