Skip to content

Commit

Permalink
增加读取json功能
Browse files Browse the repository at this point in the history
  • Loading branch information
smilelight committed Aug 22, 2024
1 parent e9b7ed3 commit 3b5d6ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lightutils/io/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
12 changes: 12 additions & 0 deletions lightutils/io/json_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import os

from tqdm import tqdm


def read_json_line(filename: str, error_file: str = None):
"""
Expand Down Expand Up @@ -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())
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests
yagmail
PyYAML
PyYAML
tqdm
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.17
0.1.18

0 comments on commit 3b5d6ae

Please sign in to comment.