import re import json import asyncio import uvicorn from contextlib import asynccontextmanager from fastapi import FastAPI import aiomysql from pymysql.converters import escape_string from playwright.async_api import async_playwright HOST = '0.0.0.0' PORT = 8000 CODE_RULE = r"^([0-9]{1,2}[A-Z])\-*([0-9]{4})|([0-9]{1,3})\-*([0-9]{4})$" store = 20153 storeIdentifier = 'LEI_SHING_HONG' auth = 'lsh' @asynccontextmanager async def lifespan(app: FastAPI): app.state.db_pool = await aiomysql.create_pool( host='localhost', port=3306, user='root', password='rxxt', db='workdata', autocommit=True, minsize=2, maxsize=12, ) yield app.state.db_pool.close() await app.state.db_pool.wait_closed() app = FastAPI(lifespan=lifespan) @app.get('/hi') def _(): return { 'version': 2.0, 'host': HOST, 'port': PORT } def getUniqueId(s: str): p = re.match(r'^.+