上传文件至 /
This commit is contained in:
70
HelperFullPlay.py
Normal file
70
HelperFullPlay.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import rapidjson as json
|
||||
from loguru import logger
|
||||
|
||||
from Config import *
|
||||
from API_TitleServer import *
|
||||
from HelperGetUserThing import implGetUser_
|
||||
from HelperUploadUserPlayLog import apiUploadUserPlaylog
|
||||
from HelperUserAll import generateFullUserAll
|
||||
|
||||
def generateMusicData():
|
||||
|
||||
return {
|
||||
"musicId": 0,
|
||||
"level": 0,
|
||||
"playCount": 0,
|
||||
"achievement": 0,
|
||||
"comboStatus": 0,
|
||||
"syncStatus": 0,
|
||||
"deluxscoreMax": 0,
|
||||
"scoreRank": 0,
|
||||
"extNum1": 0
|
||||
}
|
||||
|
||||
def applyUserAllPatches(userAll, patches):
|
||||
for key, value in patches.items():
|
||||
if isinstance(value, dict) and key in userAll and isinstance(userAll[key], dict):
|
||||
applyUserAllPatches(userAll[key], value)
|
||||
elif isinstance(value, list) and key in userAll and isinstance(userAll[key], list):
|
||||
for i, patch_item in enumerate(value):
|
||||
if i < len(userAll[key]) and isinstance(patch_item, dict) and isinstance(userAll[key][i], dict):
|
||||
applyUserAllPatches(userAll[key][i], patch_item)
|
||||
elif i >= len(userAll[key]):
|
||||
userAll[key].append(patch_item)
|
||||
else:
|
||||
userAll[key] = value
|
||||
|
||||
def implFullPlayAction(userId: int, currentLoginTimestamp:int, currentLoginResult, musicData, userAllPatches, debugMode=False):
|
||||
|
||||
currentUserData = implGetUser_("Data", userId)
|
||||
currentUserData2 = currentUserData['userData']
|
||||
|
||||
currentUploadUserPlaylogApiResult = apiUploadUserPlaylog(userId, musicData, currentUserData2, currentLoginResult['loginId'])
|
||||
logger.debug(f"上传 UserPlayLog 结果: {currentUploadUserPlaylogApiResult}")
|
||||
|
||||
retries = 0
|
||||
while retries < 3:
|
||||
currentPlaySpecial = calcPlaySpecial()
|
||||
currentUserAll = generateFullUserAll(userId, currentLoginResult, currentLoginTimestamp, currentUserData2, currentPlaySpecial)
|
||||
applyUserAllPatches(currentUserAll, userAllPatches)
|
||||
|
||||
if debugMode:
|
||||
logger.debug("调试模式:构建出的 UserAll 数据:" + json.dumps(currentUserAll, indent=4))
|
||||
logger.info("Bye!")
|
||||
return
|
||||
|
||||
data = json.dumps(currentUserAll)
|
||||
try:
|
||||
currentUserAllResult = json.loads(apiSDGB(data, "UpsertUserAllApi", userId))
|
||||
except SDGBRequestError:
|
||||
logger.warning("上传 UserAll 出现 500. 重建数据.")
|
||||
retries += 1
|
||||
continue
|
||||
except Exception:
|
||||
raise SDGBApiError("邪门错误")
|
||||
break
|
||||
else:
|
||||
raise SDGBRequestError
|
||||
|
||||
logger.info("上机:结果:"+ str(currentUserAllResult))
|
||||
return currentUserAllResult
|
||||
Reference in New Issue
Block a user