添加了计时器

This commit is contained in:
MarkusJoe
2022-04-05 20:48:50 +08:00
parent cbf311ba6a
commit f181a0c6cf
2 files changed
+27 -1

No files matched your search

+2 -1
View File
@@ -9,8 +9,10 @@
import os import os
import sys import sys
import requests import requests
from ..decorators import time_it
@time_it
def download(): def download():
res = requests.get('https://markusjoe.github.io/static_file_hosting/data.sqlite') res = requests.get('https://markusjoe.github.io/static_file_hosting/data.sqlite')
with open('./app/db/data.sqlite', 'wb') as fp: with open('./app/db/data.sqlite', 'wb') as fp:
@@ -22,7 +24,6 @@ if __name__ != '__main__':
print('数据库文件未找到, 正在下载中') print('数据库文件未找到, 正在下载中')
try: try:
download() download()
print('下载完成')
except Exception as error: except Exception as error:
print('下载失败, 错误原因:', error) print('下载失败, 错误原因:', error)
print('请手动下载数据库文件到 ./app/db/data.sqlite') print('请手动下载数据库文件到 ./app/db/data.sqlite')
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/4/5
# @File Name: decorators.py
import time
from functools import wraps
def time_it(func):
@wraps(func)
def wrapper(*args, **kwargs):
print('数据库文件开始下载')
start = time.time()
result = func(*args, **kwargs)
end = time.time()
print('下载结束, 耗时 {}'.format(round(end - start, 2)))
return result
return wrapper