2022-09-11 11:41:31 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -- coding:utf-8 --
|
|
|
|
|
# @Author: markushammered@gmail.com
|
|
|
|
|
# @Development Tool: PyCharm
|
|
|
|
|
# @Create Time: 2022/8/30
|
|
|
|
|
# @File Name: response.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from src.db import Database
|
|
|
|
|
|
|
|
|
|
|
2022-12-30 16:42:03 +08:00
|
|
|
async def resp(_id: str, length: int = 7, theme: str = "lewd") -> dict:
|
2022-09-11 11:41:31 +08:00
|
|
|
"""
|
2022-11-11 18:47:24 +08:00
|
|
|
generate dict response
|
|
|
|
|
include all information
|
2022-09-18 09:20:19 +08:00
|
|
|
:param _id: name
|
|
|
|
|
:param length: length for counter
|
|
|
|
|
:param theme: theme for counter
|
2022-09-11 11:41:31 +08:00
|
|
|
:return:
|
|
|
|
|
"""
|
2022-12-22 18:10:02 +08:00
|
|
|
result = await Database().query(_id)
|
|
|
|
|
times = result[1]
|
2022-09-11 11:41:31 +08:00
|
|
|
str_number = str(times) # 将整形转换为字符串
|
|
|
|
|
len_number = len(str_number) # 再获取字符串长度
|
2022-12-30 16:42:03 +08:00
|
|
|
g_length = length * "0" # 根据输入的位数来生成0的数量
|
2022-09-11 11:41:31 +08:00
|
|
|
show_number = str(g_length[:-len_number] + str_number)
|
|
|
|
|
context = []
|
2022-12-30 16:42:03 +08:00
|
|
|
headers = {"cache-control": "max-age=0, no-cache, no-store, must-revalidate",
|
|
|
|
|
"Content-Type": "image/svg+xml; charset=utf-8"}
|
2022-12-22 18:10:02 +08:00
|
|
|
data = await Database().query_image(theme)
|
2024-06-21 13:25:09 +08:00
|
|
|
height = data[0]["height"]
|
|
|
|
|
width = data[0]["width"]
|
2022-09-18 09:20:19 +08:00
|
|
|
counter = 0
|
|
|
|
|
for i, n in zip(data, show_number):
|
|
|
|
|
context.append({
|
2024-06-21 13:25:09 +08:00
|
|
|
"position": i["width"] * counter,
|
|
|
|
|
"width": i["width"],
|
|
|
|
|
"height": i["height"],
|
|
|
|
|
"base64": data[int(n)]["base64"]
|
2022-09-18 09:20:19 +08:00
|
|
|
})
|
|
|
|
|
counter += 1
|
2022-09-11 11:41:31 +08:00
|
|
|
|
2022-09-18 09:20:19 +08:00
|
|
|
return {
|
2022-12-30 16:42:03 +08:00
|
|
|
"context": context,
|
|
|
|
|
"g_width": length * width,
|
|
|
|
|
"g_height": height,
|
|
|
|
|
"headers": headers
|
2022-09-18 09:20:19 +08:00
|
|
|
}
|