配置文件改回yml

This commit is contained in:
Elaina 2024-10-21 19:28:22 +08:00
parent 2e31ba8b52
commit 0a6826687e
2 changed files with 15 additions and 4 deletions

View file

@ -309,7 +309,6 @@ class DepotManager:
latest_count = int(count.count) latest_count = int(count.count)
if category == "K未分类" and latest_count == 0: if category == "K未分类" and latest_count == 0:
continue continue
result[category][translation.name] = { result[category][translation.name] = {
"number": latest_count, "number": latest_count,

View file

@ -5,7 +5,9 @@ from threading import Event
from typing import TYPE_CHECKING, Any, Optional from typing import TYPE_CHECKING, Any, Optional
import requests import requests
import yaml
from pydantic import BaseModel from pydantic import BaseModel
from yamlcore import CoreDumper, CoreLoader
from mower.utils.config.conf import Conf from mower.utils.config.conf import Conf
from mower.utils.config.plan import PlanModel from mower.utils.config.plan import PlanModel
@ -15,13 +17,22 @@ if TYPE_CHECKING:
from mower.utils.device.device import Device from mower.utils.device.device import Device
from mower.utils.recognize import Recognizer from mower.utils.recognize import Recognizer
conf_path = get_path("@app/conf.json") # conf_path = get_path("@app/conf.json")
conf_path = get_path("@app/conf.yml")
plan_path = get_path("@app/plan.json") plan_path = get_path("@app/plan.json")
def save_conf(): def save_conf():
with conf_path.open("w", encoding="utf8") as f: with conf_path.open("w", encoding="utf8") as f:
json.dump(conf.model_dump(), f, ensure_ascii=False, indent=4) # Use json.dump # json.dump(conf.model_dump(), f, ensure_ascii=False, indent=4) # Use json.dump
yaml.dump(
conf.model_dump(),
f,
Dumper=CoreDumper,
encoding="utf-8",
default_flow_style=False,
allow_unicode=True,
)
def load_conf(): def load_conf():
@ -32,7 +43,8 @@ def load_conf():
save_conf() save_conf()
return return
with conf_path.open("r", encoding="utf-8") as f: with conf_path.open("r", encoding="utf-8") as f:
conf = Conf(**json.load(f)) # conf = Conf(**json.load(f))
conf = Conf(**yaml.load(f, Loader=CoreLoader))
conf: Conf conf: Conf