зеркало из
https://github.com/viginum-datalab/twscrape.git
synced 2025-10-29 21:16:25 +02:00
fix: cli --raw response in json string (was stringified python dict)
Этот коммит содержится в:
родитель
cd0a8198d0
Коммит
8ccf3b6357
@ -3,6 +3,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
|
|
||||||
@ -27,6 +28,12 @@ def get_fn_arg(args):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def to_str(doc):
|
||||||
|
# doc is httpx.Response or twscrape.User / twscrape.Tweet
|
||||||
|
# both have .json method but with different return type
|
||||||
|
return doc if isinstance(doc, str) else json.dumps(doc.json(), default=str)
|
||||||
|
|
||||||
|
|
||||||
async def main(args):
|
async def main(args):
|
||||||
if args.debug:
|
if args.debug:
|
||||||
set_log_level("DEBUG")
|
set_log_level("DEBUG")
|
||||||
@ -67,10 +74,10 @@ async def main(args):
|
|||||||
|
|
||||||
if "limit" in args:
|
if "limit" in args:
|
||||||
async for doc in fn(val, limit=args.limit):
|
async for doc in fn(val, limit=args.limit):
|
||||||
print(doc.json())
|
print(to_str(doc))
|
||||||
else:
|
else:
|
||||||
doc = await fn(val)
|
doc = await fn(val)
|
||||||
print(doc.json())
|
print(to_str(doc))
|
||||||
|
|
||||||
|
|
||||||
def custom_help(p):
|
def custom_help(p):
|
||||||
|
|||||||
Загрузка…
x
Ссылка в новой задаче
Block a user