Archived
更新
This commit is contained in:
4 files changed
+61
-27
No files matched your search
+17
-9
@@ -9,21 +9,29 @@
|
||||
import os
|
||||
import requests
|
||||
from flask import Flask
|
||||
from config import config
|
||||
from .main import main
|
||||
from .db.db import SQLite
|
||||
|
||||
|
||||
class Config:
|
||||
"""基类配置"""
|
||||
JSON_SORT_KEYS = False
|
||||
JSON_AS_ASCII = False
|
||||
|
||||
|
||||
def create_app():
|
||||
def create_app(config_name):
|
||||
"""创建主app"""
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config[config_name])
|
||||
config[config_name].init_app(app)
|
||||
|
||||
app.register_blueprint(main)
|
||||
app.config.from_object(Config)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def download():
|
||||
res = requests.get('https://syncdatabase.herokuapp.com/sync/')
|
||||
with open('./app/db/data.db', 'wb') as fp:
|
||||
fp.write(res.content)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not os.path.exists('./app/db/data.db'):
|
||||
print('数据库文件未找到, 正在下载中')
|
||||
download()
|
||||
print('下载完成')
|
||||
+2
-1
@@ -8,6 +8,7 @@
|
||||
|
||||
import sqlite3
|
||||
from typing import List
|
||||
from config import Config
|
||||
|
||||
|
||||
class SQLite:
|
||||
@@ -18,7 +19,7 @@ class SQLite:
|
||||
初始化SQLite对象
|
||||
完成后会自动提交, 自动关闭
|
||||
"""
|
||||
self.__path = './app/db/data.db'
|
||||
self.__path = Config.SQLALCHEMY_DATABASE_URI
|
||||
self.__conn = sqlite3.connect(self.__path)
|
||||
self.__cursor = self.__conn.cursor()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user