This repository has been archived on 2026-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RequestCounter/bin/utils/view.py
T

81 lines
3.4 KiB
Python
Raw Permalink Normal View History

2022-02-18 19:30:54 +08:00
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/18
2022-02-18 19:35:46 +08:00
# @File Name: view.py
2022-02-18 19:30:54 +08:00
import sqlite3
from flask import render_template
from db.sqlite import fetch_style_data
2022-02-18 20:18:38 +08:00
from db.sqlite import fetch_table
2022-02-18 19:30:54 +08:00
2022-02-18 20:30:17 +08:00
def view_template(style: str, length: int, name: str, count: str) -> str or tuple[bool, str]:
2022-02-18 19:30:54 +08:00
"""
渲染模板
:param count:
:param name:
:param length:
:param style:
:return:
"""
2022-02-18 20:18:38 +08:00
if style not in fetch_table():
2022-02-18 20:30:17 +08:00
return [False, 'BadLength']
origin_data = fetch_style_data(style) # 获取数据库内的文件
2022-02-18 19:30:54 +08:00
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)