添加了更多的主题, 修复了输入不存在主题时报错
No files matched your search
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
import time
|
||||
from gevent import pywsgi
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from flask import Response
|
||||
@@ -14,11 +15,46 @@ from flask import make_response
|
||||
from flask import send_from_directory
|
||||
from bin.core.render_ import render_temp_
|
||||
from bin.core.b64img import re_sort_number_image
|
||||
from db.db import (fetch_data, update_data)
|
||||
from db.db import (fetch_data,
|
||||
update_data,
|
||||
fetch_table)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
def get_theme_list() -> Response:
|
||||
"""
|
||||
直接获取可选主题
|
||||
:return:
|
||||
"""
|
||||
table_list = fetch_table()
|
||||
response = make_response({'code': 200,
|
||||
'msg': '可用主题如下',
|
||||
'themes': table_list})
|
||||
response.status_code = 200
|
||||
response.headers['Content-Type'] = 'application/json: charset=utf-8'
|
||||
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate'
|
||||
response.headers['date'] = time.ctime()
|
||||
return response
|
||||
|
||||
|
||||
def error_theme(theme: str) -> Response:
|
||||
"""
|
||||
错误的主题
|
||||
:param theme:
|
||||
:return:
|
||||
"""
|
||||
table_list = fetch_table()
|
||||
response = make_response({'code': -2,
|
||||
'msg': f'数据库内没有选择的主题: {theme}. 可用主题如下',
|
||||
'themes': table_list})
|
||||
response.status_code = 200
|
||||
response.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate'
|
||||
response.headers['date'] = time.ctime()
|
||||
return response
|
||||
|
||||
|
||||
def error_length(length: int) -> Response:
|
||||
"""
|
||||
数值太长显示此页面
|
||||
@@ -26,7 +62,7 @@ def error_length(length: int) -> Response:
|
||||
:return:
|
||||
"""
|
||||
response = make_response({'code': -2,
|
||||
'message': f'错误的长度: {length}'})
|
||||
'msg': f'错误的长度: {length}'})
|
||||
response.status_code = 200
|
||||
response.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate'
|
||||
@@ -42,7 +78,7 @@ def too_lang_to_count(name: str) -> Response:
|
||||
"""
|
||||
update_data(name, 0)
|
||||
response = make_response({'code': -2,
|
||||
'message': f'当前长度超过了最大可计数长度:10. 已将重置该名称的计数器'})
|
||||
'msg': '当前长度超过了最大可计数长度:10. 已将重置该名称的计数器'})
|
||||
response.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate'
|
||||
response.headers['date'] = time.ctime()
|
||||
@@ -55,7 +91,7 @@ def arg_not_be_full() -> Response:
|
||||
:return:
|
||||
"""
|
||||
response = make_response({'code': -2,
|
||||
'message': '参数填写不完整或填写错误'})
|
||||
'msg': '参数填写不完整或填写错误'})
|
||||
response.status_code = 200
|
||||
response.headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate'
|
||||
@@ -63,7 +99,7 @@ def arg_not_be_full() -> Response:
|
||||
return response
|
||||
|
||||
|
||||
def build_page(name: str, length: int, theme: str) -> list[Response] | list[bool | str] | list[bool]:
|
||||
def build_page(name: str, length: int, theme: str) -> list[bool | Response] | list[bool | str] | bool:
|
||||
"""
|
||||
渲染最终的页面
|
||||
:param theme:
|
||||
@@ -76,8 +112,11 @@ def build_page(name: str, length: int, theme: str) -> list[Response] | list[bool
|
||||
return [False, too_lang_to_count(name)]
|
||||
if 7 <= length <= 10:
|
||||
zero_count = '0' * (length - len(str(count))) + str(count)
|
||||
sorted_image, width, height = re_sort_number_image(zero_count, theme)
|
||||
status, sorted_image, width, height = re_sort_number_image(zero_count, theme)
|
||||
if status:
|
||||
return [True, render_temp_(length, name, sorted_image, width, height)]
|
||||
else:
|
||||
return [False, 'BadTheme']
|
||||
else:
|
||||
return [False, 'BadLength']
|
||||
|
||||
@@ -92,6 +131,8 @@ def api_page() -> Response | str:
|
||||
name = str(args.get('name')).replace('None', 'null')
|
||||
length = args.get('length')
|
||||
theme = args.get('theme')
|
||||
if theme == 'ls':
|
||||
return get_theme_list()
|
||||
if name and name != 'null':
|
||||
if not length:
|
||||
length = 7
|
||||
@@ -108,6 +149,8 @@ def api_page() -> Response | str:
|
||||
return response
|
||||
elif build_page_result[1] == 'BadLength':
|
||||
return error_length(length)
|
||||
elif build_page_result[1] == 'BadTheme':
|
||||
return error_theme(theme)
|
||||
else:
|
||||
return build_page_result[1]
|
||||
else:
|
||||
|
||||
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 7.5 KiB |
@@ -0,0 +1,8 @@
|
||||
由于图片过多暂且不放置原图
|
||||
所有图片均在theme.db中 以base64编码保存
|
||||
theme.db 使用的是Sqlite 数据库
|
||||
- 数据类型:
|
||||
- k text -> 索引
|
||||
- v text -> base64编码
|
||||
- w integer -> 图片宽
|
||||
- h integer -> 图片高
|
||||
|
Before Width: | Height: | Size: 8.3 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1016 B |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 183 B |
|
Before Width: | Height: | Size: 142 B |
|
Before Width: | Height: | Size: 161 B |
|
Before Width: | Height: | Size: 977 B |
|
Before Width: | Height: | Size: 171 B |
|
Before Width: | Height: | Size: 163 B |
|
Before Width: | Height: | Size: 174 B |
|
Before Width: | Height: | Size: 147 B |
|
Before Width: | Height: | Size: 178 B |
|
Before Width: | Height: | Size: 175 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |