def main(): print("获取抽卡记录", end="...", flush=True) gachaInfo = getGachaInfo() gachaTypes = getGachaTypes() gachaTypeIds = [banner["key"] for banner in gachaTypes] gachaTypeNames = [banner["name"] for banner in gachaTypes] gachaTypeDict = dict(zip(gachaTypeIds, gachaTypeNames)) gachaData = {} gachaData["gachaType"] = gachaTypes gachaData["gachaInfo"] = gachaInfo gachaData["gachaLog"] = {} for gachaTypeId in gachaTypeIds: gachaLog = getGachaLogs(gachaTypeId) gachaData["gachaLog"][gachaTypeId] = gachaLog print(gachaTypeDict[gachaTypeId], end=" ", flush=True) print("") uid_flag = 1 for gachaType in gachaData["gachaLog"]: for log in gachaData["gachaLog"][gachaType]: if uid_flag and log["uid"]: gachaData["uid"] = log["uid"] uid_flag = 0 # del log["uid"] # del log["count"] # del log["gacha_type"] print("写入文件", end="...", flush=True) gen_path = os.path.dirname(os.path.realpath(sys.argv[0])) with open(f"{gen_path}\\gachaData.json", "w", encoding="utf-8") as f: f.write(str(gachaData).replace("'", '"')) print("JSON", flush=True) if s.getKey("FLAG_CLEAN"): print("清除记录", end="...", flush=True) gen_path = os.path.dirname(os.path.realpath(sys.argv[0])) del_paths = [ name for name in os.listdir(gen_path) if name.startswith("gacha") and ( name.endswith(".csv") or name.endswith(".xlsx")) ] for del_path in del_paths: try: os.remove(gen_path + "\\" + del_path) print(del_path, end=" ", flush=True) except: pass print("") if s.getKey("FLAG_WRITE_XLSX"): import writeXLSX writeXLSX.main() if s.getKey("FLAG_SHOW_REPORT"): import statisticsData statisticsData.main()
def main(): print("获取抽卡记录", flush=True) # gachaInfo = getGachaInfo() gachaTypes = getGachaTypes() gachaTypeIds = [banner["key"] for banner in gachaTypes] gachaTypeNames = [banner["name"] for banner in gachaTypes] gachaTypeDict = dict(zip(gachaTypeIds, gachaTypeNames)) gachaData = {} gachaData["gachaType"] = gachaTypes # gachaData["gachaInfo"] = gachaInfo gachaData["gachaLog"] = {} for gachaTypeId in gachaTypeIds: gachaLog = getGachaLogs(gachaTypeId, gachaTypeDict) gachaData["gachaLog"][gachaTypeId] = gachaLog uid_flag = 1 for gachaType in gachaData["gachaLog"]: for log in gachaData["gachaLog"][gachaType]: if uid_flag and log["uid"]: gachaData["uid"] = log["uid"] uid_flag = 0 # del log["uid"] # del log["count"] # del log["gacha_type"] gen_path = os.path.dirname(os.path.realpath(sys.argv[0])) uid = gachaData["uid"] localDataFilePath = f"{gen_path}\\gachaData-{uid}.json" if os.path.isfile(localDataFilePath): with open(localDataFilePath, "r", encoding="utf-8") as f: localData = json.load(f) mergeData = mergeDataFunc(localData, gachaData) else: mergeData = gachaData print("写入文件", end="...", flush=True) with open(f"{gen_path}\\gachaData.json", "w", encoding="utf-8") as f: json.dump(mergeData, f, ensure_ascii=False, sort_keys=False, indent=4) with open(f"{gen_path}\\gachaData-{uid}.json", "w", encoding="utf-8") as f: json.dump(mergeData, f, ensure_ascii=False, sort_keys=False, indent=4) print("JSON", flush=True) t = time.strftime("%Y%m%d%H%M%S", time.localtime()) with open(f"{gen_path}\\gachaData-{uid}-{t}.json", "w", encoding="utf-8") as f: json.dump(gachaData, f, ensure_ascii=False, sort_keys=False, indent=4) if s.getKey("FLAG_CLEAN"): print("清除记录", end="...", flush=True) gen_path = os.path.dirname(os.path.realpath(sys.argv[0])) del_paths = [name for name in os.listdir(gen_path) if name.startswith("gacha") and (name.endswith(".csv") or name.endswith(".xlsx"))] for del_path in del_paths: try: os.remove(gen_path + "\\" + del_path) print(del_path, end=" ", flush=True) except: pass print("") if s.getKey("FLAG_WRITE_XLSX"): import writeXLSX writeXLSX.main() if s.getKey("FLAG_SHOW_REPORT"): import statisticsData statisticsData.main()
def main(): print("获取抽卡记录", flush=True) gachaData = {} gachaData["gachaLog"] = {} for gachaTypeId in gachaQueryTypeIds: gachaLog = getGachaLogs(gachaTypeId) gachaData["gachaLog"][gachaTypeId] = gachaLog uid_flag = 1 for gachaType in gachaData["gachaLog"]: for log in gachaData["gachaLog"][gachaType]: if uid_flag and log["uid"]: gachaData["uid"] = log["uid"] uid_flag = 0 # del log["uid"] # del log["count"] # del log["gacha_type"] gen_path = os.path.dirname(os.path.realpath(sys.argv[0])) uid = gachaData["uid"] localDataFilePath = f"{gen_path}\\gachaData-{uid}.json" if os.path.isfile(localDataFilePath): with open(localDataFilePath, "r", encoding="utf-8") as f: localData = json.load(f) mergeData = mergeDataFunc(localData, gachaData) else: mergeData = gachaData mergeData["gachaType"] = gachaQueryTypeDict print("写入JSON", end="...", flush=True) # 抽卡报告读取 gachaData.json with open(f"{gen_path}\\gachaData.json", "w", encoding="utf-8") as f: json.dump(mergeData, f, ensure_ascii=False, sort_keys=False, indent=4) # 待合并数据 gachaData-{uid}.json with open(f"{gen_path}\\gachaData-{uid}.json", "w", encoding="utf-8") as f: json.dump(mergeData, f, ensure_ascii=False, sort_keys=False, indent=4) # 备份历史数据防止爆炸 gachaData-{uid}-{t}.json t = time.strftime("%Y%m%d%H%M%S", time.localtime()) with open(f"{gen_path}\\gachaData-{uid}-{t}.json", "w", encoding="utf-8") as f: json.dump(mergeData, f, ensure_ascii=False, sort_keys=False, indent=4) print("OK", flush=True) if s.getKey("FLAG_AUTO_ARCHIVE"): print("自动归档...", flush=True) archive_path = f"{gen_path}\\archive" if not os.path.exists(archive_path): os.mkdir(archive_path) files = os.listdir(gen_path) archive_UIGF = [ f for f in files if re.match(r"UIGF_gachaData-\d+-\d+.json", f) ] archive_json = [ f for f in files if re.match(r"gachaData-\d+-\d+.json", f) ] archive_xlsx = [ f for f in files if re.match(r"gachaExport-\d+.xlsx", f) ] archive_files = archive_UIGF + archive_json + archive_xlsx for file in archive_files: try: shutil.move(f"{gen_path}\\{file}", f"{archive_path}\\") print(file, flush=True) except Exception as e: print(e) try: os.remove(f"{archive_path}\\{file}") except: pass if s.getKey("FLAG_UIGF_JSON"): print("写入UIGF JSON", end="...", flush=True) with open(f"{gen_path}\\UIGF_gachaData-{uid}-{t}.json", "w", encoding="utf-8") as f: UIGF_data = UIGF_converter.convert(uid) json.dump(UIGF_data, f, ensure_ascii=False, sort_keys=False, indent=4) print("OK", flush=True) if s.getKey("FLAG_WRITE_XLSX"): import writeXLSX writeXLSX.main() if s.getKey("FLAG_SHOW_REPORT"): import render_html render_html.main() pressAnyKeyToExit()