implement masterdata utils

master
wlt233 7 months ago
parent da02f3e69f
commit 3b6fde8333

Binary file not shown.

@ -1,15 +1,19 @@
from sanic import Blueprint
from .api import bp_sif_api
from .login import bp_sif_login
from .user import bp_sif_user
from .misc import bp_sif_misc
from .download import bp_sif_download
from .api import bp_sif_api
from .live import bp_sif_live
from .unit import bp_sif_unit
bp_sif = Blueprint.group(bp_sif_login,
bp_sif_user,
bp_sif_misc,
bp_sif_download,
bp_sif_api,
bp_sif_live,
bp_sif_unit,
url_prefix="main.php")

@ -53,5 +53,6 @@ async def pack_resp(f, *args, **kw):
})
def common_api(f):
return check_token(parse_data(pack_resp(f)))

@ -36,7 +36,7 @@ async def batch(request: Request):
request_data = request.ctx.request_data
static_root = Sanic.get_app().config["STATIC_ROOT"]
download_resp = []
resp = []
if request_data.get("client_version", "") == Sanic.get_app().config["PACKAGE_VERSION"]: # 97.4.6
package_type = request_data.get("package_type", 0)
excluded_package_ids = request_data.get("excluded_package_ids", [])
@ -46,11 +46,11 @@ async def batch(request: Request):
if package_id in excluded_package_ids: continue
package_order_list.sort(key=lambda x: x[0])
for package_order, package_size in package_order_list:
download_resp.append({
resp.append({
"size": package_size,
"url": f"{static_root}/{os}/{package_type}_{package_id}_{package_order}.zip"
})
return download_resp
return resp
@ -62,19 +62,19 @@ async def update(request: Request):
version = Sanic.get_app().config["PACKAGE_VERSION"]
target_os = request_data.get("target_os", "")
download_resp = []
resp = []
if request_data.get("external_version", "") != version: # 97.4.6
package_type = 99
package_dict = Sanic.get_app().ctx.assets_list[target_os][package_type]
for package_id, package_order_list in package_dict.items():
package_order_list.sort(key=lambda x: x[0])
for package_order, package_size in package_order_list:
download_resp.append({
resp.append({
"size": package_size,
"url": f"{static_root}/{target_os}/{package_type}_{package_id}_{package_order}.zip",
"version": version
})
return download_resp
return resp

@ -0,0 +1,74 @@
from sanic import Blueprint, Request
import time
from .common import common_api
from utils.masterdata import get_masterdata
bp_sif_live = Blueprint("sif_live", url_prefix="live")
@bp_sif_live.route("liveStatus", methods=["POST"])
@common_api
async def liveStatus(request: Request):
normal_live_status_list = []
live_difficulty_id = get_masterdata("live.db", "normal_live_m", ["live_difficulty_id"])
for t in live_difficulty_id:
normal_live_status_list.append({
"live_difficulty_id": t[0],
"status": 1,
"hi_score": 0,
"hi_combo_count": 0,
"clear_cnt": 0,
"achieved_goal_id_list": []
})
special_live_status_list = []
live_difficulty_id = get_masterdata("live.db", "special_live_m", ["live_difficulty_id"])
for t in live_difficulty_id:
special_live_status_list.append({
"live_difficulty_id": t[0],
"status": 1,
"hi_score": 0,
"hi_combo_count": 0,
"clear_cnt": 0,
"achieved_goal_id_list": []
})
resp = {
"normal_live_status_list": normal_live_status_list,
"special_live_status_list": special_live_status_list,
"training_live_status_list": [],
"marathon_live_status_list": [],
"free_live_status_list": [],
"can_resume_live": True
}
return resp
@bp_sif_live.route("schedule", methods=["POST"])
@common_api
async def schedule(request: Request):
live_list = []
live_difficulty_id = get_masterdata("live.db", "special_live_m", ["live_difficulty_id"])
for t in live_difficulty_id:
live_list.append({
"live_difficulty_id": 46,
"start_date": "2000-01-01 00:00:00",
"end_date": "2099-01-01 00:00:00",
"is_random": False
})
resp = {
"event_list": [],
"live_list": live_list,
"limited_bonus_list": [],
"limited_bonus_common_list": [],
"random_live_list": [],
"free_live_list": [],
"training_live_list": []
}
return resp

@ -40,11 +40,11 @@ async def authkey(request: Request):
# f"version=1.1&nonce={nonce}&"
# f"requestTimeStamp={int(time.time())}")
auth_resp = {
resp = {
"authorize_token": authorize_token,
"dummy_token": server_token
}
return auth_resp
return resp
@ -76,7 +76,7 @@ async def login(request: Request):
ctx = Sanic.get_app().ctx
if not hasattr(ctx, "auth_token"): ctx.auth_token = {}
ctx.auth_token[user.user_id] = new_authorize_token
login_resp = {
resp = {
"authorize_token": new_authorize_token,
"user_id": user.user_id,
"review_version": "",
@ -85,5 +85,5 @@ async def login(request: Request):
"skip_login_news": False,
"adult_flag": 2
}
return login_resp
return resp

@ -13,12 +13,12 @@ bp_sif_misc = Blueprint("sif_misc")
@bp_sif_misc.route("/gdpr/get", methods=["POST"])
@common_api
async def gdpr_get(request: Request):
gdpr_resp = {
resp = {
"enable_gdpr": True,
"is_eea": False,
"server_timestamp": int(time.time())
}
return gdpr_resp
return resp
@ -39,7 +39,7 @@ async def lbonus_execute(request: Request):
}
}
lbonus_resp = {
resp = {
"sheets": [],
"calendar_info": {
"current_date": "2006-01-02 03:04:05",
@ -87,14 +87,14 @@ async def lbonus_execute(request: Request):
"server_timestamp": int(time.time()),
"present_cnt": 0,
}
return lbonus_resp
return resp
@bp_sif_misc.route("/personalnotice/get", methods=["POST"])
@common_api
async def personalnotice_get(request: Request):
notice_resp = {
resp = {
"has_notice": False,
"notice_id": 0,
"type": 0,
@ -102,7 +102,7 @@ async def personalnotice_get(request: Request):
"contents": "",
"server_timestamp": int(time.time()),
}
return notice_resp
return resp
@bp_sif_misc.route("/personalnotice/agree", methods=["POST"])
@common_api
@ -113,16 +113,16 @@ async def personalnotice_agree(request: Request):
@bp_sif_misc.route("/tos/tosCheck", methods=["POST"])
@common_api
async def tos_toscheck(request: Request):
notice_resp = {
async def tos_tosCheck(request: Request):
resp = {
"tos_id": 1,
"tos_type": 1,
"is_agreed": True,
"server_timestamp": int(time.time()),
}
return notice_resp
return resp
@bp_sif_misc.route("/tos/tosAgree", methods=["POST"])
@common_api
async def tos_tosagree(request: Request):
async def tos_tosAgree(request: Request):
return {}

@ -0,0 +1,17 @@
from sanic import Blueprint, Request
import time
from .common import common_api
bp_sif_name = Blueprint("sif_name", url_prefix="name")
@bp_sif_name.route("", methods=["POST"])
@common_api
async def _(request: Request):
resp = {}
return resp

@ -0,0 +1,52 @@
from sanic import Blueprint, Request
import time
from .common import common_api
bp_sif_unit = Blueprint("sif_unit", url_prefix="unit")
@bp_sif_unit.route("unitAll", methods=["POST"])
@common_api
async def unitAll(request: Request):
### TODO - PLACEHOLDER ###
active = []
for i in range(9):
active.append({
"unit_owning_user_id": 38383+i,
"unit_id": i+1,
"exp": 8000,
"next_exp": 0,
"level": 40,
"max_level": 40,
"level_limit_id": 0,
"rank": 1,
"max_rank": 2,
"love": 50,
"max_love": 50,
"unit_skill_exp": 0,
"unit_skill_level": 0,
"max_hp": 3,
"unit_removable_skill_capacity": 0,
"favorite_flag": False,
"display_rank": 2,
"is_rank_max": False,
"is_love_max": False,
"is_level_max": False,
"is_signed": False,
"is_skill_level_max": False,
"is_removable_skill_capacity_max": False,
"insert_date": "2023-03-13 11:47:24"
})
resp = {
"active": active,
"waiting": []
}
return resp

@ -13,7 +13,7 @@ bp_sif_user = Blueprint("sif_user", url_prefix="user")
@bp_sif_user.route("userInfo", methods=["POST"])
@common_api
async def userinfo(request: Request):
userinfo_resp = {
resp = {
"user": {
"user_id": request.ctx.user_id,
"name": "wlt233",
@ -50,4 +50,4 @@ async def userinfo(request: Request):
},
"server_timestamp": int(time.time())
}
return userinfo_resp
return resp

@ -0,0 +1,9 @@
import sqlite3
def get_masterdata(db: str, table: str, columns: list[str]) -> list[tuple]:
con = sqlite3.connect(f"./data/masterdata/{db}")
cur = con.cursor()
query = f"select {','.join(columns)} from {table}"
res = cur.execute(query).fetchall()
con.close()
return res
Loading…
Cancel
Save