Archived
添加了创建文件夹的代码
This commit is contained in:
3 files changed
+18
-67
No files matched your search
@@ -1,24 +0,0 @@
|
||||
[11:53:29] |app.py[<module>line:124] |INFO |I: 服务器已在 http://127.0.0.1:5000 运行
|
||||
[11:54:17] |app.py[<module>line:131] |INFO |I: 程序已退出
|
||||
[11:54:20] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[11:56:15] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[11:57:38] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[11:58:26] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[11:58:54] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[11:58:57] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[11:59:26] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[11:59:30] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[11:59:33] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[11:59:45] |__init__.py[<module>line:138] |ERROR |没有检测到本地主题数据库即将开始下载
|
||||
[11:59:47] |__init__.py[downloadline:80] |INFO |数据库大小: 0.0Mb. 下载线程: 3
|
||||
[11:59:47] |__init__.py[check_md5line:66] |INFO |本地数据库md5: d41d8cd98f00b204e9800998ecf8427e
|
||||
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[11:59:47] |__init__.py[check_md5line:68] |ERROR |下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载
|
||||
I: 本次下载将使用单线程下载
|
||||
[11:59:49] |__init__.py[single_downloadline:118] |INFO |正在使用单线程下载中
|
||||
[11:59:49] |__init__.py[single_downloadline:121] |INFO |下载完成 正在检验文件md5
|
||||
[11:59:49] |__init__.py[single_downloadline:126] |INFO |本地数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[11:59:49] |__init__.py[single_downloadline:131] |INFO |md5检验已通过
|
||||
[11:59:49] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[12:00:19] |app.py[<module>line:131] |INFO |程序已退出
|
||||
@@ -1,30 +0,0 @@
|
||||
[12:00:21] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[12:00:22] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[12:00:31] |__init__.py[<module>line:139] |ERROR |没有检测到本地主题数据库即将开始下载
|
||||
[12:00:32] |__init__.py[downloadline:80] |INFO |数据库大小: 0.0Mb. 下载线程: 3
|
||||
[12:00:32] |__init__.py[check_md5line:66] |INFO |本地数据库md5: d41d8cd98f00b204e9800998ecf8427e
|
||||
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[12:00:32] |__init__.py[check_md5line:68] |ERROR |下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载
|
||||
I: 本次下载将使用单线程下载
|
||||
[12:00:35] |__init__.py[single_downloadline:118] |INFO |正在使用单线程下载中
|
||||
[12:00:35] |__init__.py[single_downloadline:121] |INFO |下载完成 正在检验文件md5
|
||||
[12:00:35] |__init__.py[single_downloadline:126] |INFO |本地数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[12:00:35] |__init__.py[single_downloadline:127] |INFO |远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[12:00:35] |__init__.py[single_downloadline:132] |INFO |md5检验已通过
|
||||
[12:00:36] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[12:00:54] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[12:01:02] |__init__.py[<module>line:139] |ERROR |没有检测到本地主题数据库即将开始下载
|
||||
[12:01:03] |__init__.py[downloadline:80] |INFO |数据库大小: 0.0Mb. 下载线程: 3
|
||||
[12:01:03] |__init__.py[check_md5line:66] |INFO |本地数据库md5: d41d8cd98f00b204e9800998ecf8427e
|
||||
I: 远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[12:01:03] |__init__.py[check_md5line:68] |ERROR |下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载
|
||||
I: 本次下载将使用单线程下载
|
||||
[12:01:03] |__init__.py[single_downloadline:117] |INFO |正在使用单线程下载中
|
||||
[12:01:05] |__init__.py[single_downloadline:121] |INFO |下载完成 正在检验文件md5
|
||||
[12:01:06] |__init__.py[single_downloadline:126] |INFO |本地数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[12:01:06] |__init__.py[single_downloadline:127] |INFO |远程数据库md5: 1731a1ec76b6e8279512d2476d497c9d
|
||||
[12:01:06] |__init__.py[single_downloadline:132] |INFO |md5检验已通过
|
||||
[12:01:06] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[12:06:07] |app.py[<module>line:131] |INFO |程序已退出
|
||||
[12:06:10] |app.py[<module>line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行
|
||||
[12:06:10] |app.py[<module>line:131] |INFO |程序已退出
|
||||
+18
-13
@@ -11,6 +11,7 @@ import hashlib
|
||||
import sys
|
||||
import requests
|
||||
import threading
|
||||
from bin.utils.logger import logger
|
||||
|
||||
|
||||
class MulThreadDownload(threading.Thread):
|
||||
@@ -30,12 +31,12 @@ class MulThreadDownload(threading.Thread):
|
||||
多线程下载
|
||||
:return:
|
||||
"""
|
||||
print(f'I: 线程: Thread-{self.name} 开始下载')
|
||||
logger.info(f'线程: Thread-{self.name} 开始下载')
|
||||
headers = {"Range": "bytes=%s-%s" % (self.startpos, self.endpos)}
|
||||
res = self.session.get(self.url, headers=headers)
|
||||
self.fd.seek(self.startpos)
|
||||
self.fd.write(res.content)
|
||||
print(f'I: 线程: Thread-{self.name} 结束下载')
|
||||
logger.info(f'线程: Thread-{self.name} 结束下载')
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
@@ -62,21 +63,22 @@ class Check:
|
||||
data = fp.read()
|
||||
local_md5 = hashlib.md5(data).hexdigest()
|
||||
remote_md5 = self.session.get(self.remote_md5).json()['data'][0]
|
||||
print(f'I: 本地数据库md5: {local_md5}\nI: 远程数据库md5: {remote_md5}')
|
||||
logger.info(f'本地数据库md5: {local_md5}')
|
||||
logger.info(f'远程数据库md5: {remote_md5}')
|
||||
if local_md5 != remote_md5:
|
||||
print('E: 下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载\nI: 本次下载将使用单线程下载')
|
||||
logger.error('下载错误: 本地数据库md5和远程数据库md5检验不通过, 即将开始重新下载\nI: 本次下载将使用单线程下载')
|
||||
single_download(self.assets_url)
|
||||
else:
|
||||
print('I: md5检验已通过')
|
||||
logger.info('md5检验已通过')
|
||||
|
||||
def download(self):
|
||||
"""
|
||||
开始下载
|
||||
:return:
|
||||
"""
|
||||
filesize = int(self.session.head(self.assets_url).headers['Content-Length'])
|
||||
filesize = int(self.session.get(self.assets_url).headers['Content-Length'])
|
||||
threaded_count = 3
|
||||
print(f'I: 数据库大小: {round(filesize / 1024 / 1024, 2)}Mb. 下载线程: {threaded_count}')
|
||||
logger.info(f'数据库大小: {round(filesize / 1024 / 1024, 2)}Mb. 下载线程: {threaded_count}')
|
||||
threading.BoundedSemaphore(threaded_count)
|
||||
step = filesize // threaded_count
|
||||
mtd_list = []
|
||||
@@ -113,24 +115,27 @@ def single_download(url):
|
||||
"""
|
||||
session = requests.Session()
|
||||
session.trust_env = False
|
||||
logger.info(f'正在使用单线程下载中')
|
||||
resp = session.get(url)
|
||||
print(f'I: 正在使用单线程下载中')
|
||||
with open('./bin/assets/theme.db', 'wb') as fp:
|
||||
fp.write(resp.content)
|
||||
print('I: 下载完成 正在检验文件md5')
|
||||
logger.info('下载完成 正在检验文件md5')
|
||||
with open('./bin/assets/theme.db', 'rb') as fp:
|
||||
data = fp.read()
|
||||
local_md5 = hashlib.md5(data).hexdigest()
|
||||
remote_md5 = session.get('https://themedatabases.vercel.app/md5').json()['data'][0]
|
||||
print(f'I: 本地数据库md5: {local_md5}\nI: 远程数据库md5: {remote_md5}')
|
||||
logger.info(f'本地数据库md5: {local_md5}')
|
||||
logger.info(f'远程数据库md5: {remote_md5}')
|
||||
if local_md5 != remote_md5:
|
||||
print('E: md5检验未通过请手动前往 https://themedatabases.vercel.app/assets 下载文件并放入./bin/assets文件夹内')
|
||||
logger.error('md5检验未通过请手动前往 https://themedatabases.vercel.app/assets 下载文件并放入./bin/assets文件夹内')
|
||||
sys.exit(-1)
|
||||
else:
|
||||
print('I: md5检验已通过')
|
||||
logger.info('md5检验已通过')
|
||||
|
||||
|
||||
if __name__ != '__main__':
|
||||
if os.path.exists('./app.py') and not os.path.exists('./bin/log'):
|
||||
os.mkdir('./bin/log')
|
||||
if not os.path.exists('./bin/assets/theme.db'):
|
||||
print('E: 没有检测到本地主题数据库即将开始下载')
|
||||
logger.error('没有检测到本地主题数据库即将开始下载')
|
||||
Check().download()
|
||||
Reference in New Issue
Block a user