1 Star 2 Fork 0

打补丁的狮子 / guitar_365_practice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tool_update_cdinfos.py 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
daixb 提交于 2023-10-20 13:53 . 更新
import sys
import os
from dbmanager import *
from __defines__ import *
import json
def update_cdinfos(jsonpath: str, is_elec: bool, dbm: DataManager):
"""更新CD信息
Args:
jsonpath (str): json文件路径
is_elec (bool): 是否是电吉他
dbm (DataManager): 数据库管理对象
Raises:
Exception: 异常
"""
try:
with open(jsonpath, "r", encoding="utf-8") as f:
cdinfo_json = json.loads(f.read())
for week in range(1, 53):
if str(week) in cdinfo_json:
days = cdinfo_json[str(week)]
if len(days) >= 7:
start_seconds = 0
end_seconds = -1
for dayindex in reversed(range(0, 7)):
info = days[dayindex]
if len(info) >= 2:
start_seconds = info[0]
dbm.add_and_update_cdinfo(
key=build_week_day_key(week, dayindex, is_elec),
start_second=start_seconds,
end_second=end_seconds,
bpm=info[1],
)
Logger.debug(
f"{week} {dayindex} {is_elec} {start_seconds, end_seconds}, {info[0:2]}"
)
end_seconds = start_seconds - 1
else:
raise Exception("无效的数据")
except Exception as e:
Logger.warning("更新CDInfo出现异常:", e)
if "__main__" == __name__:
create_db_and_tables(DBCONNECTION)
dbm = DataManager(dbconnection=DBCONNECTION)
elec_cd_path = os.path.join(ELECTRIC_GUITAR_RESOURCES_ABS_DIR, "cd.json")
update_cdinfos(jsonpath=elec_cd_path, is_elec=True, dbm=dbm)
acou_cd_path = os.path.join(ACOUSTIC_GUITAR_RESOURCES_ABS_DIR, "cd.json")
update_cdinfos(jsonpath=acou_cd_path, is_elec=False, dbm=dbm)
dbm.commit()
Python
1
https://gitee.com/PatchLion_admin/guitar_365_practice.git
git@gitee.com:PatchLion_admin/guitar_365_practice.git
PatchLion_admin
guitar_365_practice
guitar_365_practice
dev

搜索帮助