From 55ddd2f4ed64af9d544ab843cff84a581dd290f4 Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Fri, 18 Feb 2022 19:30:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/__init__.py | 6 ++ bin/utils/b64img.py | 70 ----------------------- bin/utils/packlog.py | 6 ++ bin/utils/render_.py | 123 ----------------------------------------- bin/utils/view.py | 81 +++++++++++++++++++++++++++ static/cache/.gitkeep | 0 templates/index10.html | 16 ------ templates/index7.html | 13 ----- templates/index8.html | 14 ----- templates/index9.html | 15 ----- templates/view.html | 10 ++++ 11 files changed, 103 insertions(+), 251 deletions(-) create mode 100644 bin/__init__.py delete mode 100644 bin/utils/b64img.py create mode 100644 bin/utils/packlog.py delete mode 100644 bin/utils/render_.py create mode 100644 bin/utils/view.py create mode 100644 static/cache/.gitkeep delete mode 100644 templates/index10.html delete mode 100644 templates/index7.html delete mode 100644 templates/index8.html delete mode 100644 templates/index9.html create mode 100644 templates/view.html diff --git a/bin/__init__.py b/bin/__init__.py new file mode 100644 index 0000000..c022218 --- /dev/null +++ b/bin/__init__.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +# -- coding:utf-8 -- +# @Author: markushammered@gmail.com +# @Development Tool: PyCharm +# @Create Time: 2022/2/17 +# @File Name: __init__.py \ No newline at end of file diff --git a/bin/utils/b64img.py b/bin/utils/b64img.py deleted file mode 100644 index 6619b12..0000000 --- a/bin/utils/b64img.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/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.sqlite 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: # 通过elif语句依次判断数字 - 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]) # 直接将0返回 - return [True, final_b64_img_code, width_list[0], height_list[0]] - - -if __name__ != '__main__': - conn = sqlite3.connect('./db/style.db', check_same_thread=False) - cursor = conn.cursor() diff --git a/bin/utils/packlog.py b/bin/utils/packlog.py new file mode 100644 index 0000000..7979712 --- /dev/null +++ b/bin/utils/packlog.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +# -- coding:utf-8 -- +# @Author: markushammered@gmail.com +# @Development Tool: PyCharm +# @Create Time: 2022/2/18 +# @File Name: packlog.py \ No newline at end of file diff --git a/bin/utils/render_.py b/bin/utils/render_.py deleted file mode 100644 index 7568f45..0000000 --- a/bin/utils/render_.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/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]}' - ) diff --git a/bin/utils/view.py b/bin/utils/view.py new file mode 100644 index 0000000..854fbd9 --- /dev/null +++ b/bin/utils/view.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# -- coding:utf-8 -- +# @Author: markushammered@gmail.com +# @Development Tool: PyCharm +# @Create Time: 2022/2/18 +# @File Name: sort_image.py + + +import sqlite3 +from flask import render_template +from db.sqlite import fetch_style_data + + +def view_template(style: str, length: int, name: str, count: str): + """ + 渲染模板 + :param count: + :param name: + :param length: + :param style: + :return: + """ + try: + origin_data = fetch_style_data(style) # 获取数据库内的文件 + except sqlite3.OperationalError: + return False, False + context = [] + if count != '0000000000': + for i in count: # 通过elif语句依次判断数字 + if i == '0': + context.append({'base64': origin_data[0]['base64'], + 'width': origin_data[0]['width'], + 'height': origin_data[0]['height']}) + elif i == '1': + context.append({'base64': origin_data[1]['base64'], + 'width': origin_data[1]['width'], + 'height': origin_data[1]['height']}) + elif i == '2': + context.append({'base64': origin_data[2]['base64'], + 'width': origin_data[2]['width'], + 'height': origin_data[2]['height']}) + elif i == '3': + context.append({'base64': origin_data[3]['base64'], + 'width': origin_data[3]['width'], + 'height': origin_data[3]['height']}) + elif i == '4': + context.append({'base64': origin_data[4]['base64'], + 'width': origin_data[4]['width'], + 'height': origin_data[4]['height']}) + elif i == '5': + context.append({'base64': origin_data[5]['base64'], + 'width': origin_data[5]['width'], + 'height': origin_data[5]['height']}) + elif i == '6': + context.append({'base64': origin_data[6]['base64'], + 'width': origin_data[6]['width'], + 'height': origin_data[6]['height']}) + elif i == '7': + context.append({'base64': origin_data[7]['base64'], + 'width': origin_data[7]['width'], + 'height': origin_data[7]['height']}) + elif i == '8': + context.append({'base64': origin_data[8]['base64'], + 'width': origin_data[8]['width'], + 'height': origin_data[8]['height']}) + elif i == '9': + context.append({'base64': origin_data[9]['base64'], + 'width': origin_data[9]['width'], + 'height': origin_data[9]['height']}) + + for p, i in zip(context, range(0, length)): + p['position'] = i * p['width'] + + general_width = origin_data[0]['width'] * length + general_height = origin_data[0]['height'] + + return True, render_template('view.html', + context=context, + title=name, + general_height=general_height, + general_width=general_width) diff --git a/static/cache/.gitkeep b/static/cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/templates/index10.html b/templates/index10.html deleted file mode 100644 index 8d6accc..0000000 --- a/templates/index10.html +++ /dev/null @@ -1,16 +0,0 @@ - - - {{ title }} - - - - - - - - - - - - - diff --git a/templates/index7.html b/templates/index7.html deleted file mode 100644 index 59dafb5..0000000 --- a/templates/index7.html +++ /dev/null @@ -1,13 +0,0 @@ - - - {{ title }} - - - - - - - - - - diff --git a/templates/index8.html b/templates/index8.html deleted file mode 100644 index 98a9fbf..0000000 --- a/templates/index8.html +++ /dev/null @@ -1,14 +0,0 @@ - - - {{ title }} - - - - - - - - - - - diff --git a/templates/index9.html b/templates/index9.html deleted file mode 100644 index 73caae2..0000000 --- a/templates/index9.html +++ /dev/null @@ -1,15 +0,0 @@ - - - {{ title }} - - - - - - - - - - - - diff --git a/templates/view.html b/templates/view.html new file mode 100644 index 0000000..4bdcfcb --- /dev/null +++ b/templates/view.html @@ -0,0 +1,10 @@ + + + + + $Title$ + + +$END$ + + \ No newline at end of file