From 114c13a6f75fd33200ff0d6d9308dcb2375ca0c5 Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Sun, 11 Sep 2022 11:41:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E6=B2=A1=E6=9C=89=E6=B7=BB=E5=8A=A0Content-Type?= =?UTF-8?q?=E8=80=8C=E5=AF=BC=E8=87=B4markdown=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=98=BE=E7=A4=BA=E5=9B=BE=E7=89=87=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/response.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/utils/response.py diff --git a/src/utils/response.py b/src/utils/response.py new file mode 100644 index 0000000..7a90e94 --- /dev/null +++ b/src/utils/response.py @@ -0,0 +1,41 @@ +#!/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: + """ + return a response + :param _id: + :param length: + :param theme: + :return: + """ + times = Database().query(_id)[1] + str_number = str(times) # 将整形转换为字符串 + len_number = len(str_number) # 再获取字符串长度 + g_length = length * '0' # 根据输入的位数来自动生成0的数量 + show_number = str(g_length[:-len_number] + str_number) + context = [] + w_h = Database().query_image(theme + '/0')[0] + count = 0 # 计数器, 每次遍历一次则加一, 让图片x轴相乘 + for i in show_number: + data = Database().query_image(theme + '/' + i)[0] + context.append({'position': data[-2] * count, + 'width': data[-2], + 'height': data[-1], + 'base64': data[1]}) + count += 1 + headers = {'cache-control': 'max-age=0, no-cache, no-store, must-revalidate', + 'Content-Type': 'image/svg+xml; charset=utf-8'} + + return {'context': context, + 'g_width': length * w_h[-2], + 'g_height': w_h[-1], + 'headers': headers}