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()
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
# -- coding:utf-8 --
|
||||
# @Author: markushammered@gmail.com
|
||||
# @Development Tool: PyCharm
|
||||
# @Create Time: 2022/3/26
|
||||
# @File Name: config.py
|
||||
|
||||
|
||||
class Config:
|
||||
JSON_SORT_KEYS = False
|
||||
JSON_AS_ASCII = False
|
||||
SQLALCHEMY_DATABASE_URI = './app/db/data.db'
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
@staticmethod
|
||||
def init_app(app):
|
||||
pass
|
||||
|
||||
|
||||
class DevelopmentConfig(Config):
|
||||
DEBUG = True
|
||||
|
||||
|
||||
class ProductionConfig(Config):
|
||||
DEBUG = False
|
||||
|
||||
|
||||
config = {
|
||||
'development': DevelopmentConfig,
|
||||
'production': ProductionConfig,
|
||||
|
||||
'default': ProductionConfig
|
||||
}
|
||||
@@ -6,25 +6,17 @@
|
||||
# @File Name: manage.py
|
||||
|
||||
|
||||
import os
|
||||
import requests
|
||||
from gevent import pywsgi
|
||||
from app import create_app
|
||||
|
||||
app = create_app()
|
||||
|
||||
|
||||
def download():
|
||||
res = requests.get('http://resource-base.herokuapp.com/download/data.db')
|
||||
with open('./app/db/data.db', 'wb') as fp:
|
||||
fp.write(res.content)
|
||||
|
||||
|
||||
if not os.path.exists('./app/db/data.db'):
|
||||
print('数据库文件未找到, 正在下载中')
|
||||
download()
|
||||
print('下载完成')
|
||||
app = create_app('default')
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('服务运行在 http://127.0.0.1:5000')
|
||||
try:
|
||||
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
print('已退出')
|
||||
except OSError:
|
||||
print('5000 端口已被占用')
|
||||
Reference in New Issue
Block a user