2022-09-29 11:28:58 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# # -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import base64
|
|
|
|
import re
|
|
|
|
from bottle import route, run, static_file, view
|
|
|
|
|
2022-09-30 20:53:40 +08:00
|
|
|
sys.path.append("../../convert/31-2")
|
2022-09-29 11:28:58 +08:00
|
|
|
from db import *
|
|
|
|
|
2022-09-30 20:53:40 +08:00
|
|
|
db.bind(provider="sqlite", filename="../../clean/31-2/data.sqlite3")
|
2022-09-29 14:29:02 +08:00
|
|
|
db.generate_mapping()
|
2022-09-29 11:28:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
@route("/<name>")
|
|
|
|
@view("weapon")
|
2022-10-03 11:17:04 +08:00
|
|
|
def weapon(name):
|
2022-09-29 11:28:58 +08:00
|
|
|
with db_session:
|
|
|
|
query = select(w for w in Melee if w.name == name)
|
2022-09-30 21:25:52 +08:00
|
|
|
if query.count() > 0:
|
|
|
|
weapon = query.first()
|
|
|
|
else:
|
|
|
|
query = select(w for w in Shield if w.name == name)
|
|
|
|
weapon = query.first()
|
|
|
|
if weapon.mechanism:
|
|
|
|
mechanism, _ = re.subn(
|
|
|
|
r"{(.*?)@(.*?)}", r"<span class='\2'>\1</span>", weapon.mechanism
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
mechanism = ""
|
2022-09-29 11:28:58 +08:00
|
|
|
stats_map = {
|
|
|
|
1: "brutality",
|
|
|
|
2: "survival",
|
|
|
|
3: "minotaur",
|
|
|
|
4: "tactics",
|
|
|
|
5: "assassin",
|
|
|
|
6: "guardian",
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
"title": name,
|
|
|
|
"icon": base64.b64encode(weapon.icon),
|
|
|
|
"mechanism": mechanism,
|
|
|
|
"description": weapon.description,
|
2022-09-30 21:25:52 +08:00
|
|
|
"stats": stats_map[weapon.stats],
|
2022-09-29 11:28:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@route("/static/<filepath:path>")
|
|
|
|
def server_static(filepath):
|
|
|
|
return static_file(filepath, root="./static")
|
|
|
|
|
|
|
|
|
|
|
|
run(host="localhost", port=8080)
|