[O] Make indent customizable
This commit is contained in:
@@ -289,7 +289,7 @@ def download_users_execute(api: API, n: float, base_dir: str, rate_limit: int,
|
|||||||
meta = {'downloaded': downloaded, 'done_set': done_set,
|
meta = {'downloaded': downloaded, 'done_set': done_set,
|
||||||
'current_set': current_set, 'next_set': next_set,
|
'current_set': current_set, 'next_set': next_set,
|
||||||
'n': n, 'rate_limit': rate_limit}
|
'n': n, 'rate_limit': rate_limit}
|
||||||
f.write(json.dumps(meta))
|
f.write(json_stringify(meta, indent=None))
|
||||||
|
|
||||||
debug(f'Finished saving friends of {screen_name}')
|
debug(f'Finished saving friends of {screen_name}')
|
||||||
debug(f'============= Total {len(downloaded)} saved =============')
|
debug(f'============= Total {len(downloaded)} saved =============')
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import json5
|
import json5
|
||||||
|
|
||||||
@@ -101,12 +102,13 @@ class EnhancedJSONEncoder(json.JSONEncoder):
|
|||||||
return super().default(o)
|
return super().default(o)
|
||||||
|
|
||||||
|
|
||||||
def json_stringify(obj) -> str:
|
def json_stringify(obj, indent: Union[int, None] = 1) -> str:
|
||||||
"""
|
"""
|
||||||
Serialize json string with support for dataclasses and datetime and sets and with custom
|
Serialize json string with support for dataclasses and datetime and sets and with custom
|
||||||
configuration.
|
configuration.
|
||||||
|
|
||||||
:param obj: Objects
|
:param obj: Objects
|
||||||
|
:param indent: Indent size or none
|
||||||
:return: Json strings
|
:return: Json strings
|
||||||
"""
|
"""
|
||||||
return json.dumps(obj, indent=1, cls=EnhancedJSONEncoder, ensure_ascii=False)
|
return json.dumps(obj, indent=indent, cls=EnhancedJSONEncoder, ensure_ascii=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user