From 9176ddc25b0299158e0c61b3d1ddb3a0decfe48a Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Fri, 11 Feb 2022 16:26:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6=E6=96=B9=E5=BC=8F,=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=9A=84=E7=8A=B6=E6=80=81=E7=A0=81?= =?UTF-8?q?=E4=B8=BA302=20=E4=BF=AE=E6=94=B9=E5=90=8E=E4=B8=BA200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 33 +++-- bin/{core => utils}/__init__.py | 14 +- bin/{core => utils}/b64img.py | 140 +++++++++--------- bin/{core => utils}/error.py | 0 bin/{core => utils}/render_.py | 246 ++++++++++++++++---------------- 5 files changed, 216 insertions(+), 217 deletions(-) rename bin/{core => utils}/__init__.py (95%) rename bin/{core => utils}/b64img.py (96%) rename bin/{core => utils}/error.py (100%) rename bin/{core => utils}/render_.py (97%) diff --git a/app.py b/app.py index 9b341ed..f0769b0 100644 --- a/app.py +++ b/app.py @@ -12,14 +12,13 @@ from flask import Flask from flask import request from flask import Response from flask import make_response -from flask import send_from_directory from flask import jsonify -from bin.core.error import ErrorProcess -from bin.core.render_ import render_temp_ -from bin.core.b64img import re_sort_number_image +from bin.utils.error import ErrorProcess +from bin.utils.render_ import render_temp_ +from bin.utils.b64img import re_sort_number_image from db.db import fetch_data -app = Flask(__name__) +app = Flask(__name__, static_url_path='') app.config['JSON_SORT_KEYS'] = False # 设置JSON消息不根据字母顺序重新排序 app.config['JSON_AS_ASCII'] = False # 设置JSON消息显示中文 @@ -31,7 +30,7 @@ def miss(reason) -> Response: :param reason: :return: """ - return jsonify({'code': 404, 'msg': f'{reason}', 'data': []}) + return jsonify({'code': 404, 'msg': f'{reason}', 'data': None}) @app.errorhandler(500) @@ -41,16 +40,7 @@ def error(reason) -> Response: :param reason: :return: """ - return jsonify({'code': 500, 'msg': f'{reason}', 'data': []}) - - -@app.route('/favicon.ico', methods=['GET', 'POST']) -def favicon() -> Response: - """ - 主页图标 - :return: - """ - return app.send_static_file('favicon.ico') + return jsonify({'code': 500, 'msg': f'{reason}', 'data': None}) def build_page(name: str, length: int, theme: str) -> list[bool or Response] or list[bool or str] or bool: @@ -111,13 +101,22 @@ def api_page() -> Response or str: return ErrorProcess().arg_not_be_full() +@app.route('/favicon.ico', methods=['GET', 'POST']) +def favicon() -> Response: + """ + 主页图标 + :return: + """ + return app.send_static_file('favicon.ico') + + @app.route('/', methods=['GET', 'POST']) def index() -> Response: """ 索引页面 :return: """ - return send_from_directory('./static', 'index.html') + return app.send_static_file('index.html') if __name__ == '__main__': diff --git a/bin/core/__init__.py b/bin/utils/__init__.py similarity index 95% rename from bin/core/__init__.py rename to bin/utils/__init__.py index ac042b8..d4c17cc 100644 --- a/bin/core/__init__.py +++ b/bin/utils/__init__.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/5 -# @File Name: __init__.py.py - +#!/usr/bin/env python3 +# -- coding:utf-8 -- +# @Author: markushammered@gmail.com +# @Development Tool: PyCharm +# @Create Time: 2022/2/5 +# @File Name: __init__.py.py + diff --git a/bin/core/b64img.py b/bin/utils/b64img.py similarity index 96% rename from bin/core/b64img.py rename to bin/utils/b64img.py index 4ed5d6f..4d26669 100644 --- a/bin/core/b64img.py +++ b/bin/utils/b64img.py @@ -1,70 +1,70 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/3 -# @File Name: b64img.py - - -import sqlite3 -from typing import Any -from db.db import fetch_table - - -def re_sort_number_image(origin_number: str, theme: str) -> tuple[bool, bool, bool, bool] or list[ - bool or list[Any] or Any]: - """ - 返回一个排列好的svg base64代码列表 - :param theme: - :param origin_number: - :return: - """ - - table_list = fetch_table() - if theme not in table_list: - return False, False, False, False - - width_list = [] - height_list = [] - b_64_list = [] - cursor.execute('select * from %(name)s' % {'name': theme}) - data = cursor.fetchall() - for i in data: - width_list.append(i[2]) - height_list.append(i[3]) - b_64_list.append(i[1]) - - final_b64_img_code = [] - if origin_number != '0000000000': - for i in origin_number: - if i == '0': - final_b64_img_code.append(b_64_list[0]) - elif i == '1': - final_b64_img_code.append(b_64_list[1]) - elif i == '2': - final_b64_img_code.append(b_64_list[2]) - elif i == '3': - final_b64_img_code.append(b_64_list[3]) - elif i == '4': - final_b64_img_code.append(b_64_list[4]) - elif i == '5': - final_b64_img_code.append(b_64_list[5]) - elif i == '6': - final_b64_img_code.append(b_64_list[6]) - elif i == '7': - final_b64_img_code.append(b_64_list[7]) - elif i == '8': - final_b64_img_code.append(b_64_list[8]) - elif i == '9': - final_b64_img_code.append(b_64_list[9]) - - return [True, final_b64_img_code, width_list[0], height_list[0]] - else: - for i in range(10): - final_b64_img_code.append(b_64_list[0]) - return [True, final_b64_img_code, width_list[0], height_list[0]] - - -if __name__ != '__main__': - conn = sqlite3.connect('./bin/assets/theme.db', check_same_thread=False) - cursor = conn.cursor() +#!/usr/bin/env python3 +# -- coding:utf-8 -- +# @Author: markushammered@gmail.com +# @Development Tool: PyCharm +# @Create Time: 2022/2/3 +# @File Name: b64img.py + + +import sqlite3 +from typing import Any +from db.db import fetch_table + + +def re_sort_number_image(origin_number: str, theme: str) -> tuple[bool, bool, bool, bool] or list[ + bool or list[Any] or Any]: + """ + 返回一个排列好的svg base64代码列表 + :param theme: + :param origin_number: + :return: + """ + + table_list = fetch_table() + if theme not in table_list: + return False, False, False, False + + width_list = [] + height_list = [] + b_64_list = [] + cursor.execute('select * from %(name)s' % {'name': theme}) + data = cursor.fetchall() + for i in data: + width_list.append(i[2]) + height_list.append(i[3]) + b_64_list.append(i[1]) + + final_b64_img_code = [] + if origin_number != '0000000000': + for i in origin_number: + if i == '0': + final_b64_img_code.append(b_64_list[0]) + elif i == '1': + final_b64_img_code.append(b_64_list[1]) + elif i == '2': + final_b64_img_code.append(b_64_list[2]) + elif i == '3': + final_b64_img_code.append(b_64_list[3]) + elif i == '4': + final_b64_img_code.append(b_64_list[4]) + elif i == '5': + final_b64_img_code.append(b_64_list[5]) + elif i == '6': + final_b64_img_code.append(b_64_list[6]) + elif i == '7': + final_b64_img_code.append(b_64_list[7]) + elif i == '8': + final_b64_img_code.append(b_64_list[8]) + elif i == '9': + final_b64_img_code.append(b_64_list[9]) + + return [True, final_b64_img_code, width_list[0], height_list[0]] + else: + for i in range(10): + final_b64_img_code.append(b_64_list[0]) + return [True, final_b64_img_code, width_list[0], height_list[0]] + + +if __name__ != '__main__': + conn = sqlite3.connect('./bin/assets/theme.db', check_same_thread=False) + cursor = conn.cursor() diff --git a/bin/core/error.py b/bin/utils/error.py similarity index 100% rename from bin/core/error.py rename to bin/utils/error.py diff --git a/bin/core/render_.py b/bin/utils/render_.py similarity index 97% rename from bin/core/render_.py rename to bin/utils/render_.py index faedea1..963ab92 100644 --- a/bin/core/render_.py +++ b/bin/utils/render_.py @@ -1,123 +1,123 @@ -#!/usr/bin/env python3 -# -- coding:utf-8 -- -# @Author: markushammered@gmail.com -# @Development Tool: PyCharm -# @Create Time: 2022/2/5 -# @File Name: render_.py - - -from flask import render_template - - -def render_temp_(length: int, name: str, image_list: list, width: int, height: int) -> str: - """ - 代码很烂写到隐蔽的地方就看不见了 - :param height: - :param width: - :param length: - :param name: - :param image_list: - :return: - """ - position_list = [] - for i in range(0, length): - position_list.append(i * width) - file_name = f'index{length}.html' - - # 自己写的都看不下去了 - if length == 7: - return render_template(file_name, - title=name, - g_width=length * width, - width=width, - height=height, - x_position_0=position_list[0], - x_position_1=position_list[1], - x_position_2=position_list[2], - x_position_3=position_list[3], - x_position_4=position_list[4], - x_position_5=position_list[5], - x_position_6=position_list[6], - svg_img_0=f'{image_list[0]}', - svg_img_1=f'{image_list[1]}', - svg_img_2=f'{image_list[2]}', - svg_img_3=f'{image_list[3]}', - svg_img_4=f'{image_list[4]}', - svg_img_5=f'{image_list[5]}', - svg_img_6=f'{image_list[6]}' - ) - elif length == 8: - return render_template(file_name, - title=name, - g_width=length * width, - width=width, - height=height, - x_position_0=position_list[0], - x_position_1=position_list[1], - x_position_2=position_list[2], - x_position_3=position_list[3], - x_position_4=position_list[4], - x_position_5=position_list[5], - x_position_6=position_list[6], - x_position_7=position_list[7], - svg_img_0=f'{image_list[0]}', - svg_img_1=f'{image_list[1]}', - svg_img_2=f'{image_list[2]}', - svg_img_3=f'{image_list[3]}', - svg_img_4=f'{image_list[4]}', - svg_img_5=f'{image_list[5]}', - svg_img_6=f'{image_list[6]}', - svg_img_7=f'{image_list[7]}' - ) - elif length == 9: - return render_template(file_name, - title=name, - g_width=length * width, - width=width, - height=height, - x_position_0=position_list[0], - x_position_1=position_list[1], - x_position_2=position_list[2], - x_position_3=position_list[3], - x_position_4=position_list[4], - x_position_5=position_list[5], - x_position_6=position_list[6], - x_position_7=position_list[7], - x_position_8=position_list[8], - svg_img_0=f'{image_list[0]}', - svg_img_1=f'{image_list[1]}', - svg_img_2=f'{image_list[2]}', - svg_img_3=f'{image_list[3]}', - svg_img_4=f'{image_list[4]}', - svg_img_5=f'{image_list[5]}', - svg_img_6=f'{image_list[6]}', - svg_img_7=f'{image_list[7]}', - svg_img_8=f'{image_list[8]}', - ) - elif length == 10: - return render_template(file_name, - title=name, - g_width=length * width, - width=width, - height=height, - x_position_0=position_list[0], - x_position_1=position_list[1], - x_position_2=position_list[2], - x_position_3=position_list[3], - x_position_4=position_list[4], - x_position_5=position_list[5], - x_position_6=position_list[6], - x_position_7=position_list[7], - x_position_8=position_list[8], - x_position_9=position_list[9], - svg_img_0=f'{image_list[0]}', - svg_img_1=f'{image_list[1]}', - svg_img_2=f'{image_list[2]}', - svg_img_3=f'{image_list[3]}', - svg_img_4=f'{image_list[4]}', - svg_img_5=f'{image_list[5]}', - svg_img_6=f'{image_list[6]}', - svg_img_7=f'{image_list[7]}', - svg_img_8=f'{image_list[8]}', - svg_img_9=f'{image_list[9]}' - ) +#!/usr/bin/env python3 +# -- coding:utf-8 -- +# @Author: markushammered@gmail.com +# @Development Tool: PyCharm +# @Create Time: 2022/2/5 +# @File Name: render_.py + + +from flask import render_template + + +def render_temp_(length: int, name: str, image_list: list, width: int, height: int) -> str: + """ + 代码很烂写到隐蔽的地方就看不见了 + :param height: + :param width: + :param length: + :param name: + :param image_list: + :return: + """ + position_list = [] + for i in range(0, length): + position_list.append(i * width) + file_name = f'index{length}.html' + + # 自己写的都看不下去了 + if length == 7: + return render_template(file_name, + title=name, + g_width=length * width, + width=width, + height=height, + x_position_0=position_list[0], + x_position_1=position_list[1], + x_position_2=position_list[2], + x_position_3=position_list[3], + x_position_4=position_list[4], + x_position_5=position_list[5], + x_position_6=position_list[6], + svg_img_0=f'{image_list[0]}', + svg_img_1=f'{image_list[1]}', + svg_img_2=f'{image_list[2]}', + svg_img_3=f'{image_list[3]}', + svg_img_4=f'{image_list[4]}', + svg_img_5=f'{image_list[5]}', + svg_img_6=f'{image_list[6]}' + ) + elif length == 8: + return render_template(file_name, + title=name, + g_width=length * width, + width=width, + height=height, + x_position_0=position_list[0], + x_position_1=position_list[1], + x_position_2=position_list[2], + x_position_3=position_list[3], + x_position_4=position_list[4], + x_position_5=position_list[5], + x_position_6=position_list[6], + x_position_7=position_list[7], + svg_img_0=f'{image_list[0]}', + svg_img_1=f'{image_list[1]}', + svg_img_2=f'{image_list[2]}', + svg_img_3=f'{image_list[3]}', + svg_img_4=f'{image_list[4]}', + svg_img_5=f'{image_list[5]}', + svg_img_6=f'{image_list[6]}', + svg_img_7=f'{image_list[7]}' + ) + elif length == 9: + return render_template(file_name, + title=name, + g_width=length * width, + width=width, + height=height, + x_position_0=position_list[0], + x_position_1=position_list[1], + x_position_2=position_list[2], + x_position_3=position_list[3], + x_position_4=position_list[4], + x_position_5=position_list[5], + x_position_6=position_list[6], + x_position_7=position_list[7], + x_position_8=position_list[8], + svg_img_0=f'{image_list[0]}', + svg_img_1=f'{image_list[1]}', + svg_img_2=f'{image_list[2]}', + svg_img_3=f'{image_list[3]}', + svg_img_4=f'{image_list[4]}', + svg_img_5=f'{image_list[5]}', + svg_img_6=f'{image_list[6]}', + svg_img_7=f'{image_list[7]}', + svg_img_8=f'{image_list[8]}', + ) + elif length == 10: + return render_template(file_name, + title=name, + g_width=length * width, + width=width, + height=height, + x_position_0=position_list[0], + x_position_1=position_list[1], + x_position_2=position_list[2], + x_position_3=position_list[3], + x_position_4=position_list[4], + x_position_5=position_list[5], + x_position_6=position_list[6], + x_position_7=position_list[7], + x_position_8=position_list[8], + x_position_9=position_list[9], + svg_img_0=f'{image_list[0]}', + svg_img_1=f'{image_list[1]}', + svg_img_2=f'{image_list[2]}', + svg_img_3=f'{image_list[3]}', + svg_img_4=f'{image_list[4]}', + svg_img_5=f'{image_list[5]}', + svg_img_6=f'{image_list[6]}', + svg_img_7=f'{image_list[7]}', + svg_img_8=f'{image_list[8]}', + svg_img_9=f'{image_list[9]}' + )