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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def resp(_id: str, length: int = 7, theme: str = 'lewd') -> dict:
|
|
|
|
|
"""
|
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-11-11 18:47:24 +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 = []
|
|
|
|
|
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)
|
2022-09-18 09:20:19 +08:00
|
|
|
height = data[0][-1]
|
|
|
|
|
width = data[0][-2]
|
|
|
|
|
counter = 0
|
|
|
|
|
for i, n in zip(data, show_number):
|
|
|
|
|
context.append({
|
|
|
|
|
'position': i[-2] * counter,
|
|
|
|
|
'width': i[-2],
|
|
|
|
|
'height': i[-1],
|
|
|
|
|
'base64': data[int(n)][1]
|
|
|
|
|
})
|
|
|
|
|
counter += 1
|
2022-09-11 11:41:31 +08:00
|
|
|
|
2022-09-18 09:20:19 +08:00
|
|
|
return {
|
|
|
|
|
'context': context,
|
|
|
|
|
'g_width': length * width,
|
|
|
|
|
'g_height': height,
|
|
|
|
|
'headers': headers
|
|
|
|
|
}
|