summaryrefslogtreecommitdiff
path: root/ATRI/utils.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-02-06 00:32:26 +0800
committerKyomotoi <[email protected]>2021-02-06 00:32:26 +0800
commitf5ceb8927f2e7f2a9e29d62c8e4cef876f917249 (patch)
tree40b9dcd6b7d3db486054e3aa9b5a04d25fa2284e /ATRI/utils.py
parenteb52fab79ada7efe6191e3a5f90179766feaded0 (diff)
downloadATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.tar.gz
ATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.tar.bz2
ATRI-f5ceb8927f2e7f2a9e29d62c8e4cef876f917249.zip
🏗 💩 更改项目结构,修复啥b BUG
Diffstat (limited to 'ATRI/utils.py')
-rw-r--r--ATRI/utils.py74
1 files changed, 0 insertions, 74 deletions
diff --git a/ATRI/utils.py b/ATRI/utils.py
deleted file mode 100644
index 961487c..0000000
--- a/ATRI/utils.py
+++ /dev/null
@@ -1,74 +0,0 @@
-import os
-import yaml
-from datetime import datetime
-from pathlib import Path
-from PIL import ImageFile
-import PIL.Image as Image
-
-from .exceptions import InvalidWriteText
-
-
-def load_yaml(file: Path) -> dict:
- '''
- 读取yaml文件
- :return: dict
- '''
- with open(file, 'r', encoding='utf-8') as f:
- data = yaml.safe_load(f)
- return data
-
-
-def count_list(lst: list, aim) -> int:
- '''
- 检查某列表中目标出现的次数
- :return: int
- '''
- count = 0
- for ele in lst:
- if ele == aim:
- count = count + 1
- return count
-
-
-def del_list_aim(lst: list, aim) -> list:
- '''
- 删除某列表中所有目标元素
- :return: list
- '''
- while aim in lst:
- lst.remove(aim)
- return lst
-
-
-def now_time() -> float:
- '''
- 获取当前时间(小时)
- :return: float
- '''
- now_ = datetime.now()
- hour = now_.hour
- minute = now_.minute
- now = hour + minute / 60
- return now
-
-def compress_image(out_file, kb=500, quality=85, k=0.9) -> str:
- '''
- 压缩图片
- :return: img file
- '''
- print(1)
- o_size = os.path.getsize(out_file) // 1024
- if o_size <= kb:
- return out_file
-
- ImageFile.LOAD_TRUNCATED_IMAGES = True # type: ignore
- while o_size > kb:
- img = Image.open(out_file)
- x, y = img.size
- out = img.resize((int(x * k), int(y * k)), Image.ANTIALIAS)
- try:
- out.save(out_file, quality=quality)
- except InvalidWriteText:
- raise InvalidWriteText('Writing file failed!')
- o_size = os.path.getsize(out_file) // 1024
- return out_file