forked from Fragrance/eaquira
refactor: patcher + fullplay workflow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import Callable
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -23,12 +24,62 @@ logging.basicConfig(
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def run_workflow(
|
||||
self: MaimaiClient,
|
||||
def music_user_all_patcher(
|
||||
musicId: int,
|
||||
unlock_music: bool = True,
|
||||
unlock_master: bool = False,
|
||||
unlock_remaster: bool = False,
|
||||
) -> Callable[[dict], None]:
|
||||
userItemList = []
|
||||
|
||||
if unlock_music:
|
||||
userItemList.append(
|
||||
0,
|
||||
{
|
||||
"itemKind": 5, # MUSIC
|
||||
"itemId": musicId,
|
||||
"stock": 1,
|
||||
"isValid": True,
|
||||
},
|
||||
)
|
||||
|
||||
if unlock_master:
|
||||
userItemList.append(
|
||||
0,
|
||||
{
|
||||
"itemKind": 6,
|
||||
"itemId": musicId, # MASTER
|
||||
"stock": 1,
|
||||
"isValid": True,
|
||||
},
|
||||
)
|
||||
|
||||
if unlock_remaster:
|
||||
userItemList.append(
|
||||
{
|
||||
"itemKind": 7,
|
||||
"itemId": musicId, # RE: MASTER
|
||||
"stock": 1,
|
||||
"isValid": True,
|
||||
}
|
||||
)
|
||||
|
||||
def merge(d: dict):
|
||||
d.update(
|
||||
{
|
||||
"userMusicDetailList": [musicData],
|
||||
"isNewMusicDetailList": "1",
|
||||
"userItemList": userItemList,
|
||||
"isNewItemList": len(userItemList) * "1",
|
||||
}
|
||||
)
|
||||
|
||||
return merge
|
||||
|
||||
|
||||
async def run_workflow(
|
||||
self: MaimaiClient,
|
||||
user_all_patcher: Callable[[dict], None],
|
||||
):
|
||||
|
||||
async with httpx.AsyncClient(verify=False) as client:
|
||||
@@ -78,46 +129,7 @@ async def run_workflow(
|
||||
loginId, loginDate, musicData, GeneralUserInfo
|
||||
)
|
||||
|
||||
userItemList = []
|
||||
|
||||
if unlock_music:
|
||||
userItemList.append(
|
||||
0,
|
||||
{
|
||||
"itemKind": 5, # MUSIC
|
||||
"itemId": musicId,
|
||||
"stock": 1,
|
||||
"isValid": True,
|
||||
},
|
||||
)
|
||||
|
||||
if unlock_master:
|
||||
userItemList.append(
|
||||
0,
|
||||
{
|
||||
"itemKind": 6,
|
||||
"itemId": musicId, # MASTER
|
||||
"stock": 1,
|
||||
"isValid": True,
|
||||
},
|
||||
)
|
||||
|
||||
if unlock_remaster:
|
||||
userItemList.append(
|
||||
{
|
||||
"itemKind": 7,
|
||||
"itemId": musicId, # RE: MASTER
|
||||
"stock": 1,
|
||||
"isValid": True,
|
||||
}
|
||||
)
|
||||
|
||||
requestData_UserAll |= {
|
||||
"userMusicDetailList": [musicData],
|
||||
"isNewMusicDetailList": "1",
|
||||
"userItemList": userItemList,
|
||||
"isNewItemList": len(userItemList) * "1",
|
||||
}
|
||||
user_all_patcher(requestData_UserAll)
|
||||
|
||||
await self.call_api(client, "UpsertUserAllApi", requestData_UserAll, userId)
|
||||
|
||||
@@ -127,12 +139,16 @@ async def run_workflow(
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
patcher = music_user_all_patcher(
|
||||
musicId=834,
|
||||
unlock_music=False,
|
||||
# unlock_master=True,
|
||||
unlock_remaster=True,
|
||||
)
|
||||
|
||||
asyncio.run(
|
||||
run_workflow(
|
||||
maimai,
|
||||
musicId=834,
|
||||
unlock_music=False,
|
||||
# unlock_master=True,
|
||||
unlock_remaster=True,
|
||||
user_all_patcher=patcher,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user