添加了更多的主题, 修复了输入不存在主题时报错

This commit is contained in:
MarkusJoe
2022-02-09 16:20:53 +08:00
parent 494cc7fea2
commit baf99a905c
317 files changed
+111 -324

No files matched your search

+50 -7
View File
@@ -7,6 +7,7 @@
import time import time
from gevent import pywsgi
from flask import Flask from flask import Flask
from flask import request from flask import request
from flask import Response from flask import Response
@@ -14,11 +15,46 @@ from flask import make_response
from flask import send_from_directory from flask import send_from_directory
from bin.core.render_ import render_temp_ from bin.core.render_ import render_temp_
from bin.core.b64img import re_sort_number_image 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__) 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: def error_length(length: int) -> Response:
""" """
数值太长显示此页面 数值太长显示此页面
@@ -26,7 +62,7 @@ def error_length(length: int) -> Response:
:return: :return:
""" """
response = make_response({'code': -2, response = make_response({'code': -2,
'message': f'错误的长度: {length}'}) 'msg': f'错误的长度: {length}'})
response.status_code = 200 response.status_code = 200
response.headers['Content-Type'] = 'application/json; charset=utf-8' response.headers['Content-Type'] = 'application/json; charset=utf-8'
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate' 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) update_data(name, 0)
response = make_response({'code': -2, response = make_response({'code': -2,
'message': f'当前长度超过了最大可计数长度:10. 已将重置该名称的计数器'}) 'msg': '当前长度超过了最大可计数长度:10. 已将重置该名称的计数器'})
response.headers['Content-Type'] = 'application/json; charset=utf-8' response.headers['Content-Type'] = 'application/json; charset=utf-8'
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate' response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate'
response.headers['date'] = time.ctime() response.headers['date'] = time.ctime()
@@ -55,7 +91,7 @@ def arg_not_be_full() -> Response:
:return: :return:
""" """
response = make_response({'code': -2, response = make_response({'code': -2,
'message': '参数填写不完整或填写错误'}) 'msg': '参数填写不完整或填写错误'})
response.status_code = 200 response.status_code = 200
response.headers['Content-Type'] = 'application/json; charset=utf-8' response.headers['Content-Type'] = 'application/json; charset=utf-8'
response.headers['cache-control'] = 'max-age=0, no-cache, no-store, must-revalidate' 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 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: :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)] return [False, too_lang_to_count(name)]
if 7 <= length <= 10: if 7 <= length <= 10:
zero_count = '0' * (length - len(str(count))) + str(count) 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)
return [True, render_temp_(length, name, sorted_image, width, height)] if status:
return [True, render_temp_(length, name, sorted_image, width, height)]
else:
return [False, 'BadTheme']
else: else:
return [False, 'BadLength'] return [False, 'BadLength']
@@ -92,6 +131,8 @@ def api_page() -> Response | str:
name = str(args.get('name')).replace('None', 'null') name = str(args.get('name')).replace('None', 'null')
length = args.get('length') length = args.get('length')
theme = args.get('theme') theme = args.get('theme')
if theme == 'ls':
return get_theme_list()
if name and name != 'null': if name and name != 'null':
if not length: if not length:
length = 7 length = 7
@@ -108,6 +149,8 @@ def api_page() -> Response | str:
return response return response
elif build_page_result[1] == 'BadLength': elif build_page_result[1] == 'BadLength':
return error_length(length) return error_length(length)
elif build_page_result[1] == 'BadTheme':
return error_theme(theme)
else: else:
return build_page_result[1] return build_page_result[1]
else: else:
Binary file not shown.
View File
Whitespace-only changes.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

+8
View File
@@ -0,0 +1,8 @@
由于图片过多暂且不放置原图
所有图片均在theme.db中 以base64编码保存
theme.db 使用的是Sqlite 数据库
- 数据类型:
- k text -> 索引
- v text -> base64编码
- w integer -> 图片宽
- h integer -> 图片高
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1016 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 977 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Loaded 100 of 317 files, more files were not shown because too many files have changed in this diff. Show more