From 8ccf3b6357e5cf15fdc5412cd84710379892e5bd Mon Sep 17 00:00:00 2001 From: Vlad Pronsky Date: Sun, 18 Jun 2023 16:24:43 +0300 Subject: [PATCH] fix: cli --raw response in json string (was stringified python dict) --- twscrape/cli.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/twscrape/cli.py b/twscrape/cli.py index ea6be77..a3ae7b3 100644 --- a/twscrape/cli.py +++ b/twscrape/cli.py @@ -3,6 +3,7 @@ import argparse import asyncio import io +import json import sqlite3 from importlib.metadata import version @@ -27,6 +28,12 @@ def get_fn_arg(args): 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): if args.debug: set_log_level("DEBUG") @@ -67,10 +74,10 @@ async def main(args): if "limit" in args: async for doc in fn(val, limit=args.limit): - print(doc.json()) + print(to_str(doc)) else: doc = await fn(val) - print(doc.json()) + print(to_str(doc)) def custom_help(p):