From b2b509e53b44cac3d3be165b051c3fb581bd1337 Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Mon, 4 Apr 2022 13:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/__init__.py | 16 +++++++++++----- app/db/db.py | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/db/__init__.py b/app/db/__init__.py index d5b32c3..a2da361 100644 --- a/app/db/__init__.py +++ b/app/db/__init__.py @@ -7,19 +7,25 @@ import os +import sys import requests def download(): - res = requests.get('https://syncdatabase.herokuapp.com/sync/') - with open('./app/db/data.db', 'wb') as fp: + res = requests.get('https://markusjoe.github.io/static_file_hosting/data.sqlite') + with open('./app/db/data.sqlite', 'wb') as fp: fp.write(res.content) if __name__ != '__main__': - if not os.path.exists('./app/db/data.db'): + if not os.path.exists('./app/db/data.sqlite'): print('数据库文件未找到, 正在下载中') - download() - print('下载完成') + try: + download() + print('下载完成') + except Exception as error: + print('下载失败, 错误原因:', error) + print('请手动下载数据库文件到 ./app/db/data.sqlite') + sys.exit(1) __all__ = ['db'] diff --git a/app/db/db.py b/app/db/db.py index 8795f5a..a4970cf 100644 --- a/app/db/db.py +++ b/app/db/db.py @@ -18,7 +18,7 @@ class SQLite: 初始化SQLite对象 完成后会自动提交, 自动关闭 """ - self.__path = './app/db/data.db' + self.__path = './app/db/data.sqlite' self.__conn = sqlite3.connect(self.__path) self.__cursor = self.__conn.cursor()