Archived
feat: upload
This commit is contained in:
7 files changed
+115
-74
No files matched your search
Binary file not shown.
@@ -18,32 +18,40 @@ from bin.b64img import re_sort_number_image
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
def is_new_user(name: str) -> str:
|
||||
def is_new_user(name: str, reset: bool = False) -> int:
|
||||
"""
|
||||
判断填入的参数是否为已有本地已有
|
||||
如果有则该名称值加一
|
||||
如果没有则新建一个
|
||||
:param reset:
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
with open('./static/data.json', 'r', encoding='utf-8') as fp:
|
||||
try:
|
||||
data = json.load(fp)
|
||||
except json.decoder.JSONDecodeError:
|
||||
with open('./static/data.json', 'w', encoding='utf-8') as init_fp:
|
||||
json.dump({}, init_fp)
|
||||
all_user = data.keys()
|
||||
try:
|
||||
if name in all_user: # 加次数
|
||||
data[name] += 1
|
||||
return str(data[name])
|
||||
if not reset:
|
||||
with open('./static/data.json', 'r', encoding='utf-8') as fp:
|
||||
try:
|
||||
data = json.load(fp)
|
||||
except json.decoder.JSONDecodeError:
|
||||
with open('./static/data.json', 'w', encoding='utf-8') as init_fp:
|
||||
json.dump({}, init_fp)
|
||||
all_user = data.keys()
|
||||
try:
|
||||
if name in all_user: # 加次数
|
||||
data[name] += 1
|
||||
return data[name]
|
||||
|
||||
else:
|
||||
data[name] = 0 # 加用户
|
||||
return str(0)
|
||||
finally:
|
||||
with open('./static/data.json', 'w', encoding='utf-8') as dump:
|
||||
json.dump(data, dump)
|
||||
else:
|
||||
data[name] = 0 # 新加名称
|
||||
return 0
|
||||
finally:
|
||||
with open('./static/data.json', 'w', encoding='utf-8') as dump:
|
||||
json.dump(data, dump)
|
||||
else:
|
||||
with open('./static/data.json', 'r', encoding='utf-8') as reset_fp:
|
||||
data = json.load(reset_fp)
|
||||
data[name] = 0 # 重置该名称的值
|
||||
with open('./static/data.json', 'w', encoding='utf-8') as reset_dump:
|
||||
json.dump(data, reset_dump)
|
||||
|
||||
|
||||
def build_page(name: str) -> str:
|
||||
@@ -53,27 +61,35 @@ def build_page(name: str) -> str:
|
||||
:return:
|
||||
"""
|
||||
count = is_new_user(name)
|
||||
|
||||
if count == 0: # 新id生成十个0
|
||||
return '0000000000'
|
||||
if len(str(count)) <= 10:
|
||||
"""
|
||||
计算出要在数字前加上几个0, 其实就是10减去数字位数
|
||||
假如当前访问数字是300, 先将整形转换为字符串, 再使用len()计算出长度
|
||||
使用10 - 去长度, 剩下的结果就是要在前面加上几个0
|
||||
"""
|
||||
zero_counter = 10 - len(str(count))
|
||||
if count != 0:
|
||||
final_number = '0' * zero_counter + str(count) # 拼接
|
||||
else:
|
||||
final_number = '0000000000'
|
||||
sorted_image = re_sort_number_image(final_number)
|
||||
return render_template('index.html',
|
||||
title=name,
|
||||
svg_img_0=f'{sorted_image[0]}',
|
||||
svg_img_1=f'{sorted_image[1]}',
|
||||
svg_img_2=f'{sorted_image[2]}',
|
||||
svg_img_3=f'{sorted_image[3]}',
|
||||
svg_img_4=f'{sorted_image[4]}',
|
||||
svg_img_5=f'{sorted_image[5]}',
|
||||
svg_img_6=f'{sorted_image[6]}',
|
||||
svg_img_7=f'{sorted_image[7]}',
|
||||
svg_img_8=f'{sorted_image[8]}',
|
||||
svg_img_9=f'{sorted_image[9]}'
|
||||
) # 渲染模板
|
||||
else:
|
||||
if len(str(count)) <= 10:
|
||||
zero_counter = 10 - len(str(count))
|
||||
final_number = '0' * zero_counter + str(count)
|
||||
sorted_image = re_sort_number_image(final_number)
|
||||
return render_template('index.html',
|
||||
title=name,
|
||||
svg_img_0=f'{sorted_image[0]}',
|
||||
svg_img_1=f'{sorted_image[1]}',
|
||||
svg_img_2=f'{sorted_image[2]}',
|
||||
svg_img_3=f'{sorted_image[3]}',
|
||||
svg_img_4=f'{sorted_image[4]}',
|
||||
svg_img_5=f'{sorted_image[5]}',
|
||||
svg_img_6=f'{sorted_image[6]}',
|
||||
svg_img_7=f'{sorted_image[7]}',
|
||||
svg_img_8=f'{sorted_image[8]}',
|
||||
svg_img_9=f'{sorted_image[9]}'
|
||||
)
|
||||
is_new_user(name, reset=True)
|
||||
return render_template('long.html',
|
||||
title=name)
|
||||
|
||||
|
||||
def arg_not_be_full() -> Response:
|
||||
@@ -81,7 +97,7 @@ def arg_not_be_full() -> Response:
|
||||
参数不完整
|
||||
:return:
|
||||
"""
|
||||
response = make_response('<h2 style="text-align: center">参数填写不完整 -> owner</h2>')
|
||||
response = make_response('<h2 style="text-align: center">参数填写不完整 -> name</h2>')
|
||||
response.status_code = 200
|
||||
return response
|
||||
|
||||
@@ -92,18 +108,10 @@ def api_page() -> Response or str:
|
||||
API页面主函数
|
||||
:return:
|
||||
"""
|
||||
if 'owner' in request.args.keys():
|
||||
owner = request.args['owner']
|
||||
if owner != '':
|
||||
html_template = build_page(owner)
|
||||
response = make_response(html_template)
|
||||
response.headers['Content-Type'] = 'image/svg+xml'
|
||||
# response.headers['Content-Type'] = 'text/html'
|
||||
return response
|
||||
else:
|
||||
return arg_not_be_full()
|
||||
if 'name' in request.args:
|
||||
return build_page(request.args['name'])
|
||||
else:
|
||||
arg_not_be_full()
|
||||
return arg_not_be_full()
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
|
||||
Binary file not shown.
+28
-24
@@ -25,28 +25,32 @@ def re_sort_number_image(origin_number: str) -> list:
|
||||
'9': 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNjQzODg4NTE2OTM3IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjgxNzki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SI4MTgwIj48L3BhdGg+PC9zdmc+'}
|
||||
|
||||
final_b64_img_code = []
|
||||
if origin_number != '0000000000':
|
||||
for i in origin_number:
|
||||
match i:
|
||||
case '0':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(str(i)))
|
||||
case '1':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '2':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '3':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '4':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '5':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '6':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '7':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '8':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '9':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
|
||||
for i in origin_number:
|
||||
match i:
|
||||
case '0':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(str(i)))
|
||||
case '1':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '2':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '3':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '4':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '5':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '6':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '7':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '8':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
case '9':
|
||||
final_b64_img_code.append(origin_b64_img_code.get(i))
|
||||
|
||||
return final_b64_img_code
|
||||
return final_b64_img_code
|
||||
else:
|
||||
for i in range(10):
|
||||
final_b64_img_code.append(origin_b64_img_code.get(str(0)))
|
||||
return final_b64_img_code
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/2/4
|
||||
# @File Name: rne.py
|
||||
|
||||
|
||||
def main(a, **kwargs):
|
||||
print(a, kwargs)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main('sd', temp=1, sd=2)
|
||||
@@ -0,0 +1 @@
|
||||
{"MarkusJoe": 26, "Mar": 3, "M": 1, "": 5, "oo": 20}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="details">
|
||||
<i>当前数字长度超过了最长统计范(10位数)围, 已将数字重置</i>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user