Archived
update: 增加了对Deta的数据库支持和修改了一点文档
This commit is contained in:
6 files changed
+44
-14
No files matched your search
@@ -13,6 +13,20 @@
|
||||
|
||||
* 暂未支持`MongoDB`
|
||||
|
||||
# 安装 & 运行
|
||||
|
||||
```bash
|
||||
$ pip3 install -r requirements.txt
|
||||
$ uvicorn src:create_app --factory or
|
||||
$ sh run.sh or
|
||||
$ python3 main.py # 两条命令等价
|
||||
```
|
||||
|
||||
# 部署到Deta
|
||||
|
||||
* ***你需要提前准备一个Deta账号***
|
||||
* [](https://go.deta.dev/deploy?repo=https://github.com/RTAkland/MoeCounter)
|
||||
|
||||
# 开源
|
||||
|
||||
- 本项目以[Apache-2.0](./LICENSE)许可开源, 即:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "MoeCounter",
|
||||
"description": "一个Python版的MoeCounter重写, 并增加了一些功能",
|
||||
"runtime": "python3.9",
|
||||
"env": [
|
||||
{
|
||||
"key": "COUNTER_DB",
|
||||
"description": "数据库类型, 默认是sqlite3, 也可以使用mysql, 格式: user:pwd@host:port/db",
|
||||
"value": "sqlite3",
|
||||
"required": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -6,15 +6,6 @@
|
||||
* 使用sqlite, 直接填写为`sqlite3` 即默认
|
||||
* 使用mysql, 需要按照以下格式填写: user:pwd@host:port/db
|
||||
|
||||
# 安装 & 运行
|
||||
|
||||
```bash
|
||||
$ pip3 install -r requirements.txt
|
||||
$ uvicorn src:create_app --factory or
|
||||
$ sh run.sh or
|
||||
$ python3 main.py # 两条命令等价
|
||||
```
|
||||
|
||||
# 使用
|
||||
|
||||
* 访问`http://127.0.0.1:8000/<any name you want>`
|
||||
|
||||
+3
-1
@@ -4,6 +4,7 @@
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/9/11
|
||||
# @File Name: config.py
|
||||
import os
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -12,4 +13,5 @@ class Config:
|
||||
sqlite3 -> sqlite3 (default)
|
||||
mysql -> user:pwd@host:port/db
|
||||
"""
|
||||
database = "sqlite3" # Database type
|
||||
database = os.getenv('COUNTER_DB') or "sqlite3" # Database type
|
||||
DETA = eval(os.getenv('DETA_RUNTIME').title()) # mark Deta
|
||||
+10
-3
@@ -12,13 +12,20 @@ from src.config import Config
|
||||
|
||||
database = Config.database # operator
|
||||
|
||||
if not os.path.exists('./src/db/data.sqlite') and \
|
||||
Config.database == 'sqlite3':
|
||||
|
||||
def download_file(path: str):
|
||||
print('Downloading database file. Please wait...')
|
||||
file_url = 'https://static.rtast.cn/data.sqlite'
|
||||
urlretrieve(file_url, './src/db/data.sqlite') # standard lib for downloading file
|
||||
urlretrieve(file_url, path) # standard lib for downloading file
|
||||
print('Download database file successfully.')
|
||||
|
||||
|
||||
if Config.DETA and Config.database == 'sqlite3':
|
||||
if not os.path.exists('/tmp/data.sqlite'):
|
||||
download_file('/tmp/data.sqlite')
|
||||
elif not Config.DETA and Config.database == 'sqlite3':
|
||||
download_file('./src/db/data.sqlite')
|
||||
|
||||
if Config.database == 'sqlite3':
|
||||
from src.db.db import SQLite as Database
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ class BaseSQL:
|
||||
class SQLite(BaseSQL):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
if Config.DETA:
|
||||
self.conn = operator.connect('/tmp/data.sqlite')
|
||||
else:
|
||||
self.conn = operator.connect('./src/db/data.sqlite')
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user