Add 'Informatics/InfLab4/' from commit '639d363dfbc85a37e6c2ba0dda202107ab3769d1'

git-subtree-dir: Informatics/InfLab4
git-subtree-mainline: a51dfe26c0
git-subtree-split: 639d363dfb
This commit is contained in:
LeterZP
2026-02-13 19:51:21 +03:00
6 changed files with 867 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import json
import yaml
def parse_json(file_name):
try:
if file_name.split(".")[-1] != "json":
print("Ошибка: тип файла должен быть json")
exit()
with open(file_name, "r", encoding="utf-8") as file:
json_file = file.read()
bin_file = json.dumps(json_file).encode("utf-8")
with open(".".join(file_name.split(".")[:-1])+"(lib).bin", "wb") as file:
file.write(bin_file)
except Exception as e:
print("Ошибка: ", e)
def unparse_bin(file_name):
try:
if file_name.split(".")[-1] != "bin":
print("Ошибка: тип файла должен быть bin")
exit()
with open(file_name, "rb") as file:
bin_file = file.read()
yaml_file = yaml.safe_load(yaml.safe_load(bin_file))
yaml_file = yaml.dump(yaml_file, allow_unicode=True)
with open(".".join(file_name.split(".")[:-1])+".yaml", "w", encoding="utf-8") as file:
file.write(yaml_file)
except Exception as e:
print("Ошибка :", e)
def json_to_yaml(file_name):
try:
parse_json(file_name)
unparse_bin(".".join(file_name.split(".")[:-1])+"(lib).bin")
except Exception as e:
print("Ошибка: ", e)
if __name__ == "__main__":
json_to_yaml("schedule.json")