Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
[0.2.0] 支持增量更新
Browse files Browse the repository at this point in the history
修复了星铁新版本无法获取抽卡记录的Bug
  • Loading branch information
AuroraZiling committed Jun 16, 2023
1 parent ffb1e9a commit 35a0957
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 49 deletions.
Binary file modified src/assets/Hoyo-Glyphs/StarRailNeue-Sans-Regular.otf
Binary file not shown.
Binary file modified src/assets/Hoyo-Glyphs/StarRailNeue-Serif-Regular.otf
Binary file not shown.
126 changes: 89 additions & 37 deletions src/modules/Core/GachaReport/gacha_report_thread.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
import os
import pathlib
import pickle
import time
Expand All @@ -19,46 +20,97 @@
class GachaReportThread(QThread):
trigger = Signal(tuple)

def __init__(self, gachaUrl, parent=None):
def __init__(self, gachaUrl, parent=None, isAdd=False):
super(GachaReportThread, self).__init__(parent)
self.uid = ""
self.region_time_zone = ""
self.gachaUrl = gachaUrl
self.isAdd = isAdd

def run(self):
SRGFExportJsonData = SRGF_DATA_MODEL
gachaList = []
for key in GACHATYPE.keys():
end_id = "0"
page = 0
while True:
apiPerUnit = updateAPI(self.gachaUrl, GACHATYPE[key], 20, page, end_id)
responsePerUnit = json.loads(requests.get(apiPerUnit).content.decode("utf-8"))
if responsePerUnit["data"]:
gachaPerResponse = responsePerUnit["data"]["list"]
if not len(gachaPerResponse):
break
self.uid = responsePerUnit['data']["list"][0]['uid']
self.region_time_zone = str(responsePerUnit['data']["region_time_zone"])
self.trigger.emit((0, f"正在获取第{str(page + 1)}页 | {key}", self.uid))
for i in gachaPerResponse:
gachaList.append(originalToSRGFListUnit(i))
end_id = responsePerUnit["data"]["list"][-1]["id"]
page += 1
self.msleep(300)
else:
self.trigger.emit((-1, f"数据获取失败", "请检查:\n你输入URL是否可用\n距离上一次在游戏内打开跃迁记录的时间间隔在一天以内"))
return
pathlib.Path(f"{utils.working_dir}/data/{self.uid}").mkdir(parents=True, exist_ok=True)
SRGFExportJsonData["info"]["export_timestamp"] = int(time.mktime(datetime.datetime.now().timetuple()))
SRGFExportJsonData["info"]["export_app"] = "asta"
SRGFExportJsonData["info"]["export_app_version"] = utils.app_version
SRGFExportJsonData["info"]["srgf_version"] = SRGF_VERSION
SRGFExportJsonData["info"]["region_time_zone"] = int(self.region_time_zone)
SRGFExportJsonData['info']['uid'] = self.uid
SRGFExportJsonData["list"] = gachaList
open(f"{utils.working_dir}/data/{self.uid}/{self.uid}_export_data.json", "w", encoding="utf-8").write(
json.dumps(SRGFExportJsonData, indent=2, sort_keys=True, ensure_ascii=False))
with open(f"{utils.working_dir}/data/{self.uid}/{self.uid}_data.pickle", 'wb') as f:
pickle.dump(SRGFExportJsonData, f)
self.trigger.emit((1, "跃迁记录更新完毕", self.uid))
if not self.isAdd:
SRGFExportJsonData = SRGF_DATA_MODEL
gachaList = []
for key in GACHATYPE.keys():
end_id = "0"
page = 0
while True:
apiPerUnit = updateAPI(self.gachaUrl, GACHATYPE[key], 20, page, end_id)
responsePerUnit = json.loads(requests.get(apiPerUnit).content.decode("utf-8"))
if responsePerUnit["data"]:
gachaPerResponse = responsePerUnit["data"]["list"]
if not len(gachaPerResponse):
break
self.uid = responsePerUnit['data']["list"][0]['uid']
self.region_time_zone = str(responsePerUnit['data']["region_time_zone"])
self.trigger.emit((0, f"正在获取第{str(page + 1)}页 | {key}", self.uid))
for i in gachaPerResponse:
gachaList.append(originalToSRGFListUnit(i))
end_id = responsePerUnit["data"]["list"][-1]["id"]
page += 1
self.msleep(300)
else:
self.trigger.emit((-1, f"数据获取失败", "请检查:\n你输入URL是否可用\n距离上一次在游戏内打开跃迁记录的时间间隔在一天以内"))
return
pathlib.Path(f"{utils.working_dir}/data/{self.uid}").mkdir(parents=True, exist_ok=True)
SRGFExportJsonData["info"]["export_timestamp"] = int(time.mktime(datetime.datetime.now().timetuple()))
SRGFExportJsonData["info"]["export_app"] = "asta"
SRGFExportJsonData["info"]["export_app_version"] = utils.app_version
SRGFExportJsonData["info"]["srgf_version"] = SRGF_VERSION
SRGFExportJsonData["info"]["region_time_zone"] = int(self.region_time_zone)
SRGFExportJsonData['info']['uid'] = self.uid
SRGFExportJsonData["list"] = gachaList
open(f"{utils.working_dir}/data/{self.uid}/{self.uid}_export_data.json", "w", encoding="utf-8").write(
json.dumps(SRGFExportJsonData, indent=2, sort_keys=True, ensure_ascii=False))
with open(f"{utils.working_dir}/data/{self.uid}/{self.uid}_data.pickle", 'wb') as f:
pickle.dump(SRGFExportJsonData, f)
self.trigger.emit((1, "跃迁记录更新完毕", self.uid))
else:
dataPath = f"{utils.working_dir}/data/{self.isAdd}/{self.isAdd}_data.pickle"
if not os.path.exists(dataPath):
self.trigger.emit((-1, f"增量更新失败",
"请检查是否对当前UID进行过全量更新"))
return
data = pickle.load(open(dataPath, 'rb'))
gachaList = data["list"]
for key in GACHATYPE.keys():
latestId = [i["id"] for i in gachaList if i["gacha_type"] == GACHATYPE[key]]
gachaTypeEnd = False
if latestId:
latestId = latestId[0]
end_id = "0"
page = 0
while True:
apiPerUnit = updateAPI(self.gachaUrl, GACHATYPE[key], 20, page, end_id)
responsePerUnit = json.loads(requests.get(apiPerUnit).content.decode("utf-8"))
if responsePerUnit["data"]:
gachaPerResponse = responsePerUnit["data"]["list"]
if not len(gachaPerResponse):
break
self.uid = responsePerUnit['data']["list"][0]['uid']
self.region_time_zone = str(responsePerUnit['data']["region_time_zone"])
self.trigger.emit((0, f"正在获取第{str(page + 1)}页 | {key}", self.uid))
for i in gachaPerResponse:
if i["id"] == latestId:
gachaTypeEnd = True
break
gachaList.append(originalToSRGFListUnit(i))
if gachaTypeEnd:
break
end_id = responsePerUnit["data"]["list"][-1]["id"]
page += 1
self.msleep(300)
else:
self.trigger.emit((-1, f"数据获取失败", "请检查:\n你输入URL是否可用\n距离上一次在游戏内打开跃迁记录的时间间隔在一天以内"))
return
data["info"]["export_app"] = "asta"
data["info"]["export_app_version"] = utils.app_version
data["info"]["srgf_version"] = SRGF_VERSION
data["info"]["region_time_zone"] = int(self.region_time_zone)
data['info']['uid'] = self.uid
data["list"] = gachaList
open(f"{utils.working_dir}/data/{self.uid}/{self.uid}_export_data.json", "w", encoding="utf-8").write(
json.dumps(data, indent=2, sort_keys=True, ensure_ascii=False))
with open(f"{utils.working_dir}/data/{self.uid}/{self.uid}_data.pickle", 'wb') as f:
pickle.dump(data, f)
self.trigger.emit((1, "跃迁记录更新完毕", self.uid))
2 changes: 1 addition & 1 deletion src/modules/Core/GachaReport/gacha_report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def getDefaultGameDataPath():
return 0, "Game Log Not found"
with open(GAME_LOG_PATH, 'r', encoding='utf-8') as f:
logFile = f.read()
match = re.match(r'Loading player data from (.*)StarRail_Data.*', logFile)
match = re.search(r'Loading player data from (.*)StarRail_Data.*', logFile)
game_path = match.group(1) if match else None
logging.info(f"[GachaReport.utils] Game Path get: {game_path}")
return game_path
Expand Down
7 changes: 3 additions & 4 deletions src/modules/Views/ViewFunctions/home_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def run(self):
self.trigger.emit(0, 0, "正在获取信息...", "未知", character1ImagePath)
self.trigger.emit(1, 0, "正在获取信息...", "未知", character1ImagePath)
upWeaponList = []
if not os.path.exists(f"{utils.working_dir}/cache/announce.json"):
downloader.downloadFromJson(ANNOUNCE_REQUEST_URL, utils.working_dir + "/cache/", "announce.json")
downloader.downloadFromJson(ANNOUNCE_ICON_REQUEST_URL, utils.working_dir + "/cache/",
"announce_icons.json")
downloader.downloadFromJson(ANNOUNCE_REQUEST_URL, utils.working_dir + "/cache/", "announce.json")
downloader.downloadFromJson(ANNOUNCE_ICON_REQUEST_URL, utils.working_dir + "/cache/",
"announce_icons.json")
downloader.downloadFromJson(ANNOUNCE_CURRENT_UP_URL, utils.working_dir + "/cache/", "current_up.json")
if os.path.exists(f"{utils.working_dir}/cache/current_up.json") and os.path.exists(f"{utils.working_dir}/cache/announce.json"):
originalCurrentUPInfo = json.loads(open(f"{utils.working_dir}/cache/current_up.json", 'r', encoding="utf-8").read())["data"]["list"]
Expand Down
6 changes: 6 additions & 0 deletions src/modules/Views/announcement_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def __init__(self, parent=None):

self.announceData = announcement_functions.get_announce_data()
self.announceIconData = announcement_functions.get_announce_icon_data()
if not self.announceData or not self.announceIconData:
logging.info("[Announcement] Get announce.json")
downloader.downloadFromJson(ANNOUNCE_REQUEST_URL, utils.working_dir + "/cache/", "announce.json")
logging.info("[Announcement] Get announce_icon.json")
downloader.downloadFromJson(ANNOUNCE_ICON_REQUEST_URL, utils.working_dir + "/cache/",
"announce_icons.json")
self.currentAnnounceHTMLPath = ""

self.headerHBox = QHBoxLayout(self)
Expand Down
Loading

0 comments on commit 35a0957

Please sign in to comment.