From 677030194ac5aee4c0c5ec0e7ce15781e65d4b45 Mon Sep 17 00:00:00 2001 From: MarkusJoe Date: Wed, 16 Feb 2022 13:12:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/log/2022-02-16#11.log | 24 ------------------------ bin/log/2022-02-16#12.log | 30 ------------------------------ bin/utils/__init__.py | 31 ++++++++++++++++++------------- 3 files changed, 18 insertions(+), 67 deletions(-) delete mode 100644 bin/log/2022-02-16#11.log delete mode 100644 bin/log/2022-02-16#12.log diff --git a/bin/log/2022-02-16#11.log b/bin/log/2022-02-16#11.log deleted file mode 100644 index ef7ea06..0000000 --- a/bin/log/2022-02-16#11.log +++ /dev/null @@ -1,24 +0,0 @@ -[11:53:29] |app.py[line:124] |INFO |I: 服务器已在 http://127.0.0.1:5000 运行 -[11:54:17] |app.py[line:131] |INFO |I: 程序已退出 -[11:54:20] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[11:56:15] |app.py[line:131] |INFO |程序已退出 -[11:57:38] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[11:58:26] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[11:58:54] |app.py[line:131] |INFO |程序已退出 -[11:58:57] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[11:59:26] |app.py[line:131] |INFO |程序已退出 -[11:59:30] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[11:59:33] |app.py[line:131] |INFO |程序已退出 -[11:59:45] |__init__.py[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[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[12:00:19] |app.py[line:131] |INFO |程序已退出 diff --git a/bin/log/2022-02-16#12.log b/bin/log/2022-02-16#12.log deleted file mode 100644 index a2ea96a..0000000 --- a/bin/log/2022-02-16#12.log +++ /dev/null @@ -1,30 +0,0 @@ -[12:00:21] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[12:00:22] |app.py[line:131] |INFO |程序已退出 -[12:00:31] |__init__.py[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[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[12:00:54] |app.py[line:131] |INFO |程序已退出 -[12:01:02] |__init__.py[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[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[12:06:07] |app.py[line:131] |INFO |程序已退出 -[12:06:10] |app.py[line:124] |INFO |服务器已在 http://127.0.0.1:5000 运行 -[12:06:10] |app.py[line:131] |INFO |程序已退出 diff --git a/bin/utils/__init__.py b/bin/utils/__init__.py index 89d7d12..b070592 100644 --- a/bin/utils/__init__.py +++ b/bin/utils/__init__.py @@ -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: 鏈湴鏁版嵁搴搈d5: {local_md5}\nI: 杩滅▼鏁版嵁搴搈d5: {remote_md5}') + logger.info(f'鏈湴鏁版嵁搴搈d5: {local_md5}') + logger.info(f'杩滅▼鏁版嵁搴搈d5: {remote_md5}') if local_md5 != remote_md5: - print('E: 涓嬭浇閿欒: 鏈湴鏁版嵁搴搈d5鍜岃繙绋嬫暟鎹簱md5妫楠屼笉閫氳繃, 鍗冲皢寮濮嬮噸鏂颁笅杞絓nI: 鏈涓嬭浇灏嗕娇鐢ㄥ崟绾跨▼涓嬭浇') + logger.error('涓嬭浇閿欒: 鏈湴鏁版嵁搴搈d5鍜岃繙绋嬫暟鎹簱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'姝e湪浣跨敤鍗曠嚎绋嬩笅杞戒腑') resp = session.get(url) - print(f'I: 姝e湪浣跨敤鍗曠嚎绋嬩笅杞戒腑') with open('./bin/assets/theme.db', 'wb') as fp: fp.write(resp.content) - print('I: 涓嬭浇瀹屾垚 姝e湪妫楠屾枃浠秏d5') + logger.info('涓嬭浇瀹屾垚 姝e湪妫楠屾枃浠秏d5') 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: 鏈湴鏁版嵁搴搈d5: {local_md5}\nI: 杩滅▼鏁版嵁搴搈d5: {remote_md5}') + logger.info(f'鏈湴鏁版嵁搴搈d5: {local_md5}') + logger.info(f'杩滅▼鏁版嵁搴搈d5: {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()