diff --git a/lightutils/io/__init__.py b/lightutils/io/__init__.py index 0135e17..3caf8b8 100644 --- a/lightutils/io/__init__.py +++ b/lightutils/io/__init__.py @@ -1,4 +1,4 @@ -from .json_file import read_json_line, write_json_line +from .json_file import read_json_line, write_json_line, get_json_list, get_std_json_list from .notification import send_email_notification from .yaml_file import load_yaml -__all__ = ['read_json_line', 'send_email_notification', 'write_json_line', 'load_yaml'] +__all__ = ['read_json_line', 'send_email_notification', 'write_json_line', 'load_yaml', 'get_json_list', 'get_std_json_list'] diff --git a/lightutils/io/json_file.py b/lightutils/io/json_file.py index 45c4b99..55247c4 100644 --- a/lightutils/io/json_file.py +++ b/lightutils/io/json_file.py @@ -1,6 +1,8 @@ import json import os +from tqdm import tqdm + def read_json_line(filename: str, error_file: str = None): """ @@ -33,3 +35,13 @@ def write_json_line(file_obj, json_obj): """ file_obj.write(json.dumps(json_obj, ensure_ascii=False)) file_obj.write('\n') + + +def get_json_list(path): + with open(path, encoding="utf8") as f: + for line in tqdm(f): + yield json.loads(line.strip()) + +def get_std_json_list(): + for line in tqdm(sys.stdin): + yield json.loads(line.strip()) diff --git a/requirements.txt b/requirements.txt index 8e4ba81..0d6ff53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ requests yagmail -PyYAML \ No newline at end of file +PyYAML +tqdm \ No newline at end of file diff --git a/version.txt b/version.txt index 44a7df2..44905e7 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.17 \ No newline at end of file +0.1.18 \ No newline at end of file