Archived
增加了更多的主题可以选择
This commit is contained in:
8 files changed
+150
-191
No files matched your search
@@ -1,133 +1,132 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -- coding:utf-8 --
|
# -- coding:utf-8 --
|
||||||
# @Author: markushammered@gmail.com
|
# @Author: markushammered@gmail.com
|
||||||
# @Development Tool: PyCharm
|
# @Development Tool: PyCharm
|
||||||
# @Create Time: 2022/2/3
|
# @Create Time: 2022/2/3
|
||||||
# @File Name: app.py
|
# @File Name: app.py
|
||||||
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import Response
|
from flask import Response
|
||||||
from flask import make_response
|
from flask import make_response
|
||||||
from flask import send_from_directory
|
from flask import send_from_directory
|
||||||
from gevent import pywsgi
|
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)
|
|
||||||
|
app = Flask(__name__)
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
|
def error_length(length: int) -> Response:
|
||||||
def error_length(length: int) -> Response:
|
"""
|
||||||
"""
|
数值太长显示此页面
|
||||||
数值太长显示此页面
|
:param length:
|
||||||
:param length:
|
:return:
|
||||||
:return:
|
"""
|
||||||
"""
|
response = make_response({'code': -2,
|
||||||
response = make_response({'code': -2,
|
'message': f'错误的长度: {length}'})
|
||||||
'message': 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'
|
response.headers['date'] = time.ctime()
|
||||||
response.headers['date'] = time.ctime()
|
return response
|
||||||
return response
|
|
||||||
|
|
||||||
|
def too_lang_to_count(name: str) -> Response:
|
||||||
def too_lang_to_count(name: str) -> Response:
|
"""
|
||||||
"""
|
数据过长重置数据
|
||||||
数据过长重置数据
|
:param name:
|
||||||
:param name:
|
:return:
|
||||||
:return:
|
"""
|
||||||
"""
|
update_data(name, 0)
|
||||||
update_data(name, 0)
|
response = make_response({'code': -2,
|
||||||
response = make_response({'code': -2,
|
'message': f'当前长度超过了最大可计数长度:10. 已将重置该名称的计数器'})
|
||||||
'message': f'当前长度超过了最大可计数长度: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()
|
return response
|
||||||
return response
|
|
||||||
|
|
||||||
|
def arg_not_be_full() -> Response:
|
||||||
def arg_not_be_full() -> Response:
|
"""
|
||||||
"""
|
参数不完整
|
||||||
参数不完整
|
:return:
|
||||||
:return:
|
"""
|
||||||
"""
|
response = make_response({'code': -2,
|
||||||
response = make_response({'code': -2,
|
'message': '参数填写不完整或填写错误'})
|
||||||
'message': '参数填写不完整或填写错误'})
|
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'
|
response.headers['date'] = time.ctime()
|
||||||
response.headers['date'] = time.ctime()
|
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[Response] | list[bool | str] | list[bool]:
|
"""
|
||||||
"""
|
渲染最终的页面
|
||||||
渲染最终的页面
|
:param theme:
|
||||||
:param theme:
|
:param name:
|
||||||
:param name:
|
:param length:
|
||||||
:param length:
|
:return:
|
||||||
:return:
|
"""
|
||||||
"""
|
count = fetch_data(name)
|
||||||
count = fetch_data(name)
|
if len(str(count)) > length:
|
||||||
if len(str(count)) > length:
|
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)
|
||||||
sorted_image = re_sort_number_image(zero_count, theme)
|
return [True, render_temp_(length, name, sorted_image, width, height)]
|
||||||
return [True, render_temp_(length, name, sorted_image, theme)]
|
else:
|
||||||
else:
|
return [False, 'BadLength']
|
||||||
return [False, 'BadLength']
|
|
||||||
|
|
||||||
|
@app.route('/get', methods=['GET', 'POST']) # 允许 GET 和 POST 方法
|
||||||
@app.route('/get', methods=['GET', 'POST']) # 允许 GET 和 POST 方法
|
def api_page() -> Response | str:
|
||||||
def api_page() -> Response | str:
|
"""
|
||||||
"""
|
API 页面函数
|
||||||
API 页面函数
|
:return:
|
||||||
:return:
|
"""
|
||||||
"""
|
args = request.args
|
||||||
args = request.args
|
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 name and name != 'null':
|
||||||
if name and name != 'null':
|
if not length:
|
||||||
if not length:
|
length = 7
|
||||||
length = 7
|
else:
|
||||||
else:
|
length = int(length)
|
||||||
length = int(length)
|
if not theme:
|
||||||
if not theme:
|
theme = 'moebooru'
|
||||||
theme = 'moebooru'
|
build_page_result = build_page(name, length, theme)
|
||||||
build_page_result = build_page(name, length, theme)
|
if build_page_result[0]:
|
||||||
if build_page_result[0]:
|
response = make_response(build_page_result[1])
|
||||||
response = make_response(build_page_result[1])
|
response.headers['Content-Type'] = 'image/svg+xml; charset=utf-8'
|
||||||
response.headers['Content-Type'] = 'image/svg+xml; 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()
|
return response
|
||||||
return response
|
elif build_page_result[1] == 'BadLength':
|
||||||
elif build_page_result[1] == 'BadLength':
|
return error_length(length)
|
||||||
return error_length(length)
|
else:
|
||||||
else:
|
return build_page_result[1]
|
||||||
return build_page_result[1]
|
else:
|
||||||
else:
|
return arg_not_be_full()
|
||||||
return arg_not_be_full()
|
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
def index():
|
||||||
def index():
|
"""
|
||||||
"""
|
索引页面
|
||||||
索引页面
|
:return:
|
||||||
:return:
|
"""
|
||||||
"""
|
return send_from_directory('./static', 'index.html')
|
||||||
return send_from_directory('./static', 'index.html')
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
if __name__ == '__main__':
|
print('服务器已在 http://127.0.0.1:5000 运行')
|
||||||
print('服务器已在 http://127.0.0.1:5000 运行')
|
try:
|
||||||
try:
|
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
|
||||||
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
|
server.serve_forever()
|
||||||
server.serve_forever()
|
except OSError:
|
||||||
except OSError:
|
print('5000 端口被占用')
|
||||||
print('5000 端口被占用')
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -- coding:utf-8 --
|
||||||
|
# @Author: markushammered@gmail.com
|
||||||
|
# @Development Tool: PyCharm
|
||||||
|
# @Create Time: 2022/2/8
|
||||||
|
# @File Name: insert_db.py
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -- coding:utf-8 --
|
||||||
|
# @Author: markushammered@gmail.com
|
||||||
|
# @Development Tool: PyCharm
|
||||||
|
# @Create Time: 2022/2/8
|
||||||
|
# @File Name: download_img.py
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -- coding:utf-8 --
|
||||||
|
# @Author: markushammered@gmail.com
|
||||||
|
# @Development Tool: PyCharm
|
||||||
|
# @Create Time: 2022/2/8
|
||||||
|
# @File Name: img_size.py
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg width="680" height="150" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<title>{{ title }}</title>
|
|
||||||
<g>
|
|
||||||
<image x="0" y="0" width="68" height="150" xlink:href="{{ svg_img_0 }}"/>
|
|
||||||
<image x="68" y="0" width="68" height="150" xlink:href="{{ svg_img_1 }}"/>
|
|
||||||
<image x="136" y="0" width="68" height="150" xlink:href="{{ svg_img_2 }}"/>
|
|
||||||
<image x="204" y="0" width="68" height="150" xlink:href="{{ svg_img_3 }}"/>
|
|
||||||
<image x="272" y="0" width="68" height="150" xlink:href="{{ svg_img_4 }}"/>
|
|
||||||
<image x="340" y="0" width="68" height="150" xlink:href="{{ svg_img_5 }}"/>
|
|
||||||
<image x="408" y="0" width="68" height="150" xlink:href="{{ svg_img_6 }}"/>
|
|
||||||
<image x="476" y="0" width="68" height="150" xlink:href="{{ svg_img_7 }}"/>
|
|
||||||
<image x="544" y="0" width="68" height="150" xlink:href="{{ svg_img_8 }}"/>
|
|
||||||
<image x="612" y="0" width="68" height="150" xlink:href="{{ svg_img_9 }}"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.0 KiB |
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg width="476" height="150" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<title>{{ title }}</title>
|
|
||||||
<g>
|
|
||||||
<image x="0" y="0" width="68" height="150" xlink:href="{{ svg_img_0 }}"/>
|
|
||||||
<image x="68" y="0" width="68" height="150" xlink:href="{{ svg_img_1 }}"/>
|
|
||||||
<image x="136" y="0" width="68" height="150" xlink:href="{{ svg_img_2 }}"/>
|
|
||||||
<image x="204" y="0" width="68" height="150" xlink:href="{{ svg_img_3 }}"/>
|
|
||||||
<image x="272" y="0" width="68" height="150" xlink:href="{{ svg_img_4 }}"/>
|
|
||||||
<image x="340" y="0" width="68" height="150" xlink:href="{{ svg_img_5 }}"/>
|
|
||||||
<image x="408" y="0" width="68" height="150" xlink:href="{{ svg_img_6 }}"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 801 B |
@@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg width="544" height="150" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<title>{{ title }}</title>
|
|
||||||
<g>
|
|
||||||
<image x="0" y="0" width="68" height="150" xlink:href="{{ svg_img_0 }}"/>
|
|
||||||
<image x="68" y="0" width="68" height="150" xlink:href="{{ svg_img_1 }}"/>
|
|
||||||
<image x="136" y="0" width="68" height="150" xlink:href="{{ svg_img_2 }}"/>
|
|
||||||
<image x="204" y="0" width="68" height="150" xlink:href="{{ svg_img_3 }}"/>
|
|
||||||
<image x="272" y="0" width="68" height="150" xlink:href="{{ svg_img_4 }}"/>
|
|
||||||
<image x="340" y="0" width="68" height="150" xlink:href="{{ svg_img_5 }}"/>
|
|
||||||
<image x="408" y="0" width="68" height="150" xlink:href="{{ svg_img_6 }}"/>
|
|
||||||
<image x="476" y="0" width="68" height="150" xlink:href="{{ svg_img_7 }}"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 885 B |
@@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg width="612" height="150" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<title>{{ title }}</title>
|
|
||||||
<g>
|
|
||||||
<image x="0" y="0" width="68" height="150" xlink:href="{{ svg_img_0 }}"/>
|
|
||||||
<image x="68" y="0" width="68" height="150" xlink:href="{{ svg_img_1 }}"/>
|
|
||||||
<image x="136" y="0" width="68" height="150" xlink:href="{{ svg_img_2 }}"/>
|
|
||||||
<image x="204" y="0" width="68" height="150" xlink:href="{{ svg_img_3 }}"/>
|
|
||||||
<image x="272" y="0" width="68" height="150" xlink:href="{{ svg_img_4 }}"/>
|
|
||||||
<image x="340" y="0" width="68" height="150" xlink:href="{{ svg_img_5 }}"/>
|
|
||||||
<image x="408" y="0" width="68" height="150" xlink:href="{{ svg_img_6 }}"/>
|
|
||||||
<image x="476" y="0" width="68" height="150" xlink:href="{{ svg_img_7 }}"/>
|
|
||||||
<image x="544" y="0" width="68" height="150" xlink:href="{{ svg_img_8 }}"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 969 B |
Reference in New Issue
Block a user