-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_func.py
27 lines (23 loc) · 1.17 KB
/
json_func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import json
def json_save_tag_kyew_add(list_tag_keyw: list, key_js: str) -> None:
with open('../tags_keywords.json', encoding='utf-8') as file_json:
data = json.load(file_json)
data[key_js].extend(list_tag_keyw)
with open('../tags_keywords.json', 'w', encoding='utf-8') as file_json:
json.dump(data, file_json, indent=4, ensure_ascii=False)
def json_upload_tuple() -> tuple:
with open('../tags_keywords.json', encoding='utf-8') as file_json:
data = json.load(file_json)
return data["tags"], data["keywords"], data
def json_clear_tag_keyword(key_js: str) -> None:
with open('../tags_keywords.json') as file_json:
data = json.load(file_json)
data[key_js].clear()
with open('../tags_keywords.json', 'w') as file_json:
json.dump(data, file_json, indent=4, ensure_ascii=False)
def json_del_tag_kyew(key_js: str, name_to_del: str) -> None:
with open('../tags_keywords.json', encoding='utf-8') as file_json:
data = json.load(file_json)
data[key_js].remove(name_to_del)
with open('../tags_keywords.json', 'w', encoding='utf-8') as file_json:
json.dump(data, file_json, indent=4, ensure_ascii=False)