diff --git a/app.py b/app.py
index 6801692..8c4b7bf 100644
--- a/app.py
+++ b/app.py
@@ -15,7 +15,6 @@ from flask import send_from_directory
from gevent import pywsgi
from bin.core.render_ import render_temp_
from bin.core.b64img import re_sort_number_image
-from bin.core.length import make_html
from db.db import (fetch_data, update_data)
app = Flask(__name__)
@@ -77,15 +76,14 @@ def build_page(name: str, length: int, theme: str) -> list[Response] | list[bool
if len(str(count)) > length:
return [False, too_lang_to_count(name)]
if 7 <= length <= 10:
- make_html(length)
zero_count = '0' * (length - len(str(count))) + str(count)
sorted_image = re_sort_number_image(zero_count, theme)
- return [True, render_temp_(length, name, sorted_image)]
+ return [True, render_temp_(length, name, sorted_image, theme)]
else:
return [False, 'BadLength']
-@app.route('/API', methods=['GET', 'POST']) # 允许 GET 和 POST 方法
+@app.route('/get', methods=['GET', 'POST']) # 允许 GET 和 POST 方法
def api_page() -> Response | str:
"""
API 页面函数
@@ -97,11 +95,11 @@ def api_page() -> Response | str:
theme = args.get('theme')
if name and name != 'null':
if not length:
- length = 8
+ length = 7
else:
length = int(length)
if not theme:
- theme = 't1'
+ theme = 'moebooru'
build_page_result = build_page(name, length, theme)
if build_page_result[0]:
response = make_response(build_page_result[1])
diff --git a/bin/assets/theme.db b/bin/assets/theme.db
index af39a48..0a58c31 100644
Binary files a/bin/assets/theme.db and b/bin/assets/theme.db differ
diff --git a/bin/assets/themes/moe_theme/README.md b/bin/assets/themes/moe_theme/README.md
index 06cf587..3070402 100644
--- a/bin/assets/themes/moe_theme/README.md
+++ b/bin/assets/themes/moe_theme/README.md
@@ -1 +1,2 @@
-# 此文件夹内的所有文件全部来自
\ No newline at end of file
+# 此文件夹内的所有文件全部来自 https://github.com/journey-ad/Moe-counter
+# 原作者: journey-ad
\ No newline at end of file
diff --git a/bin/core/b64img.py b/bin/core/b64img.py
index 0e17f6a..00f672b 100644
--- a/bin/core/b64img.py
+++ b/bin/core/b64img.py
@@ -16,15 +16,24 @@ def re_sort_number_image(origin_number: str, theme: str) -> list:
:param origin_number:
:return:
"""
+ print(theme)
if theme == 't1':
cursor.execute('select * from theme1')
- data = cursor.fetchall()
elif theme == 't2':
cursor.execute('select * from theme2')
- data = cursor.fetchall()
+ elif theme == 'gelbooru':
+ cursor.execute('select * from gelbooru')
+ elif theme == 'gelbooru-h':
+ cursor.execute('select * from gelbooruh')
+ elif theme == 'moebooru':
+ cursor.execute('select * from moebooru')
+ elif theme == 'moebooru-h':
+ cursor.execute('select * from moebooruh')
+ elif theme == 'rule34':
+ cursor.execute('select * from rule34')
else:
- cursor.execute('select * from theme1')
- data = cursor.fetchall()
+ cursor.execute('select * from rule34')
+ data = cursor.fetchall()
temp_dict = {}
for k, v in data:
temp_dict.setdefault(k, []).append(v)
@@ -63,5 +72,5 @@ def re_sort_number_image(origin_number: str, theme: str) -> list:
if __name__ != '__main__':
- conn = sqlite3.connect('./bin/res/theme.db')
- cursor = conn.cursor()
\ No newline at end of file
+ conn = sqlite3.connect('./bin/assets/theme.db')
+ cursor = conn.cursor()
diff --git a/bin/core/length.py b/bin/core/length.py
deleted file mode 100644
index 92f78db..0000000
--- a/bin/core/length.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python3
-# -- coding:utf-8 --
-# @Author: markushammered@gmail.com
-# @Development Tool: PyCharm
-# @Create Time: 2022/2/5
-# @File Name: length.py
-
-
-def make_html(length: int, svg_width: int = 45, svg_height: int = 50) -> None:
- """
- 生成html
- :param svg_height:
- :param svg_width:
- :param length:
- :return:
- """
-
- html_head = """
-"""
- html_head = html_head % {'w': length * svg_width, 'h': svg_height} # 总体宽度
- for i in range(length): # 拼接出完整的html
- html_head += svg_tag % {'x': i * svg_width, 'w': svg_width, 'h': svg_height, 'i': i}
- html_head += html_feet # 加上结尾标签
- with open('./templates/index.html', 'w', encoding='utf-8') as template_fp: # 写入文件
- template_fp.write(html_head)
diff --git a/bin/core/render_.py b/bin/core/render_.py
index 38ccedc..61a054f 100644
--- a/bin/core/render_.py
+++ b/bin/core/render_.py
@@ -9,18 +9,23 @@
from flask import render_template
-def render_temp_(length: int, name: str, image_list: list) -> str:
+def render_temp_(length: int, name: str, image_list: list, theme: str) -> str:
"""
代码很烂写到隐蔽的地方就看不见了
+ :param theme:
:param length:
:param name:
:param image_list:
:return:
"""
+ if 'gelbooru' in theme:
+ file_name = f'index{length}-spec.html'
+ else:
+ file_name = f'index{length}.html'
# 自己写的都看不下去了
if length == 7:
- return render_template('index.html',
+ return render_template(file_name,
title=name,
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
@@ -31,7 +36,7 @@ def render_temp_(length: int, name: str, image_list: list) -> str:
svg_img_6=f'{image_list[6]}'
)
elif length == 8:
- return render_template('index.html',
+ return render_template(file_name,
title=name,
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
@@ -43,7 +48,7 @@ def render_temp_(length: int, name: str, image_list: list) -> str:
svg_img_7=f'{image_list[7]}'
)
elif length == 9:
- return render_template('index.html',
+ return render_template(file_name,
title=name,
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
@@ -55,8 +60,8 @@ def render_temp_(length: int, name: str, image_list: list) -> str:
svg_img_7=f'{image_list[7]}',
svg_img_8=f'{image_list[8]}',
)
- else:
- return render_template('index.html',
+ elif length == 10:
+ return render_template(file_name,
title=name,
svg_img_0=f'{image_list[0]}',
svg_img_1=f'{image_list[1]}',
diff --git a/db/data.db b/db/data.db
index 16f07cf..57be2e2 100644
Binary files a/db/data.db and b/db/data.db differ
diff --git a/docs/.nojekyll b/docs/.nojekyll
new file mode 100644
index 0000000..e69de29
diff --git a/docs/README.md b/docs/README.md
index c91e32b..264b29a 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,6 +1,15 @@
-# 这里是`Request Counter`的文档
-虽然说项目很小根本不需要文档
+# 这里是Request Counter的文档
+> 虽然说项目很小根本不需要文档
+# 灵感来源
+[Moe-Counter](https://github.com/MarkusJoe/Moe-counter)
+> 看到这个项目感觉挺有意思就用Python写了一个 此项目中添加了原项目中没有的功能 `Length` `设置长度`
+
+# 工作原理
+使用Flask建立服务器接收请求分析获取到的数据写入数据库
+
+# 部署
+> 在部署之前你需要先安装`python3.9.x`以上的版本
## 部署到本地服务器
```shell
$ git clone https://git@github.com:MarkusJoe/RequestCounter.git
@@ -9,9 +18,8 @@
$ python3 app.py
```
-> 程序还支持自定义图片的大小需要在`./bin/core/length.py` 中修改 `make_html`函数的参数
-### 基本信息
+# 基本信息
- Python版本: `3.9.9`
- 请求方法: `GET` `POST`
- 请求地址: `/API`
@@ -20,18 +28,13 @@
- 可选参数: `theme` : `str`
-### 注意事项
+# 注意事项
- Python版能最新版就最新版
-- 项目使用了标准库`Sqlite3`进行了数据库操作某些免费部署的服务器可能不支持
+- 项目使用了标准库`Sqlite3`进行了数据库操作某些可以部署项目的服务器可能不支持例如`vercel`(可能是我不会)
-### 开源
-- 本项目以Apache-2.0许可开源, 即:
- - 你可以直接使用该项目提供的功能, 无需任何授权
- - 你可以在**注明来源版权信息**的情况下对源代码进行任意分发和修改以及衍生
-
-
-### 快速响应:
+# 快速响应
+测试用代码如下
```python
import requests
@@ -146,4 +149,14 @@ for i in range(100):
17557
16587
+
+# 关于
+## 开源
+- 本项目以Apache-2.0许可开源, 即:
+ - 你可以直接使用该项目提供的功能, 无需任何授权
+ - 你可以在**注明来源版权信息**的情况下对源代码进行任意分发和修改以及衍生
+
+## 关于此页面
+此文档由 [docsify](https://github.com/docsifyjs/docsify) 生成. docsify 是一个动态生成文档网站的工具。不同于 GitBook、Hexo 的地方是它不会生成将 .md 转成 .html 文件,所有转换工作都是在运行时进行。
+
\ No newline at end of file
diff --git a/docs/_coverpage.md b/docs/_coverpage.md
index e69de29..48956df 100644
--- a/docs/_coverpage.md
+++ b/docs/_coverpage.md
@@ -0,0 +1,13 @@
+
+
+# RequestCounter
+
+> Python版的计数器
+
+> 使用Python Flask 库完成的访问的次数计数器
+
+* 响应速度快
+* 使用Sqlite3数据库操作
+
+[GitHub](https://github.com/MarkusJoe/RequestCounter.git)
+[Get Started](#部署)
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
new file mode 100644
index 0000000..eea2f74
--- /dev/null
+++ b/docs/index.html
@@ -0,0 +1,23 @@
+
+
+