From b4a7d9ca5a11e1a89e0f5a1af3f61e79f120da8f Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Fri, 4 Feb 2022 11:56:21 +0800 Subject: [PATCH] feat: upload --- __pycache__/app.cpython-310.pyc | Bin 2956 -> 3122 bytes app.py | 108 +++++++++++++------------ bin/__pycache__/b64img.cpython-310.pyc | Bin 13512 -> 13595 bytes bin/b64img.py | 52 ++++++------ bin/tests/rne.py | 14 ++++ static/data.json | 1 + templates/long.html | 14 ++++ 7 files changed, 115 insertions(+), 74 deletions(-) create mode 100644 bin/tests/rne.py create mode 100644 templates/long.html diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index 59ff79520ebfd8010a65964fa96af0cbc85df8fa..a4561c331562e5746a9dafb0fe6fe558c893d183 100644 GIT binary patch delta 1427 zcmah|&u<$=6rMLTyI!w{ny-juaWM($ji$Z|3Ii8Fc+DX8asx{e0cV9On0}+CbvX z`q{d~0rd7|&7-)ib1Yzytb(6u6mbwsIJC-fxXVp+t44T^BUs*-dr%upFrz(~F??#D zQKaO%IKIx+r+%i~7{aG<0w-~*D}W&^CQs$8o`&1I*J2s0Z2GaK{FWcaw(`Ta3O?pN z<)mpnK+o%@q6vyb(0UjW333!DyW;K-9lnza;ebc{5ISOs1?MFTp&=Ub_ElhJCV1-< zpYKRQTWiE5b%77P|NJ(bz^)VYItyT%MdH9dWF2c~IbxCZ2~%MtB4)8shN&tOY@QGi zSxf!YwxOn&ZJ6~Jd}@+#^Z$d}z1O>gC5EU(N(p7mST}dm`?kb~i$uncaw5&M^Xt};sb5B;--rUk($#~kVVwR z9S9-h5$w@KSO-;0Q`bH5m05?P$k&BBiz4DBc7h&Z9T9Mp9TAF15RVLHME8Zd&_ava zNg~%@TknpUH0WWWOXok~k%h$A1H~n-G90YsaaR;v_8sQ8%S3a#F6pUkZ6rTr|re)hJ+3}z2xBZvQZa+oJi zp5pR0#}V|%8u2r24+~ht(H6(jAve*DI-S6A49^_Meby)>nDP*2948KdB1PZDvuj*! z6Jivf!b%Y*aq3VoK(>^u>a@PdcJ^W!G`oImD?i*+!MkjTfKB=ct?P!vrxXckBXSfd z55>nn^x1AIWOsSQj#!`9A-EtRWNp!wJ97-oOz_s9_>P1vW(E&XSnAwmgq3$8%#$KjI_&x2tP+DlMPZ+=C^ zbITxg{pA^lK1Uhx5)3?LpjQ=WL??M$ZRiJCE>hv~EW*m;dz(-+b&TkBhauXHQ@M&T{9(X_K;*-SE3(+|?m zHw8J&O8R?|6l5W^siTj88t!SMBb$Ie)d=~TP}9UTsa7aWeW(&5;%y7%0<|mE&E7XH zLXti*i^$u0(ygt=gL}lVn_KNRTYjx~r!}+P?d)c+uLq$YgqLpYZ1{`SlrndTWmC0! z>I|s~C1w6Z;?#=YL|^q(jjXCrFVIgTXR3B9^t&6KX6UQSy5m+RmnqUKlE~XGHG-Kg zlicPmS9AJH_kAUFxvR`dE&<|R>51-+7a{d`hvQ~N 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('

参数填写不完整 -> owner

') + response = make_response('

参数填写不完整 -> name

') 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']) diff --git a/bin/__pycache__/b64img.cpython-310.pyc b/bin/__pycache__/b64img.cpython-310.pyc index cee3e3d036c5d78882facd8410c084b11b8d7f89..340321632d9aefb0e3edaa932b71c050da35b9f5 100644 GIT binary patch delta 508 zcmX?+IXjClpO=@50SGQF_><^pF_ABmv1DR}a(xO$*Yac7)2*PGLB>nm~3Mr!_3IRI62ZpPoIZLjFE-0 gNF1o$Pm{Sw2uR;z$;kxj1PK+1q7q`0H<(BO08*xW2><{9 delta 480 zcmbQ8bt025pO=@50SNl1{Ylg{pU9WV=r*xJx!#2#w!fCShM9#Sg(sV-NQIH1hG_vq z4dVjF5~dpFX2yj;$jDGA2$bgq${Qi%YnYMb_<(W_IOO<&a(+1E>IHz3F*qazfpS?m z6s%ziX3!Md{E=~y;pF+oMk1Qb zx7ZR33R3e@ZZW5)mfT`4E-9M)&De}laI&sRq_PJvl$qF>7||iyHx?caCMHHMMzP83 zO=Kq@FkzW|#)QMMNEoQWPm{TbA4uO~$;kv72NEh0L?whk(i}Fq`6;D2sdkJ&UNIAp H5aR# list: '9': 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNjQzODg4NTE2OTM3IiBjbGFzcz0ia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k2ODMgMTY3LjQ1NTcgMjAwLjEyODVDNTgyLjYyMjIgNTIwLjY3MjMgNjQ3Ljk2NTcgNDcxLjY2MzYgNjcyLjQ3ODIgMzczLjY0ODR6IiBwLWlkPSI4MTgwIj48L3BhdGg+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 diff --git a/bin/tests/rne.py b/bin/tests/rne.py new file mode 100644 index 0000000..f71150d --- /dev/null +++ b/bin/tests/rne.py @@ -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) \ No newline at end of file diff --git a/static/data.json b/static/data.json index e69de29..40452ab 100644 --- a/static/data.json +++ b/static/data.json @@ -0,0 +1 @@ +{"MarkusJoe": 26, "Mar": 3, "M": 1, "": 5, "oo": 20} \ No newline at end of file diff --git a/templates/long.html b/templates/long.html new file mode 100644 index 0000000..96ce992 --- /dev/null +++ b/templates/long.html @@ -0,0 +1,14 @@ + + + + + + {{ title }} + + +
+ 当前数字长度超过了最长统计范(10位数)围, 已将数字重置 +
+ + + \ No newline at end of file