Skip to content

Commit

Permalink
Merge pull request #3 from ruchuby/develop
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
AkiChase authored Nov 12, 2022
2 parents fc5482e + 5a4c32b commit f9a4485
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import time
from shutil import rmtree

from loguru import logger
from tqdm import tqdm
Expand All @@ -21,7 +22,7 @@ def init(proxy=None):

tmp_dir = os.path.join(os.path.dirname(cur_file_path), 'tmp')
if os.path.exists(tmp_dir):
os.removedirs(tmp_dir) # 清空之前的临时下载文件夹
rmtree(tmp_dir) # 清空之前的临时下载文件夹

if not len(KeyManager.Keys.available):
logger.error('无可用密钥,请稍后重试')
Expand Down Expand Up @@ -140,19 +141,21 @@ def character_drawing():

def check_error_files(proxy=None):
path = os.path.abspath(os.path.join(os.path.dirname(cur_file_path), 'error_files.json'))
old_path = os.path.join(os.path.dirname(path), 'old_error_files.json')
try:
with open(path, encoding='utf-8') as f:
file_list = json.load(f)
except:
return

if isinstance(file_list, list) and len(file_list) > 0:
logger.info('检测到压缩失败图片路径列表, 1s后开始压缩')
os.remove(path)
compress_cover_file_list(file_list, proxy)
logger.success('文件列表压缩完成')
character_drawing()
os.system('echo \7') # 输出到终端时可以发出蜂鸣作为一种提醒
if len(input('检测到压缩失败图片路径列表,是否对该列表进行压缩?(输入任意内容则压缩)')):
os.rename(path, old_path)
compress_cover_file_list(file_list, proxy)
logger.success('文件列表压缩完成')
character_drawing()
os.remove(old_path)
os.system('echo \7') # 输出到终端时可以发出蜂鸣作为一种提醒


def command_dir(args):
Expand Down
2 changes: 1 addition & 1 deletion tinypng_unlimited/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# 避免冲突
logger.remove()
logger.add(lambda msg: tqdm.write(msg, end=''), colorize=True,
format='<level>{time:YYYY-MM-DD hh:mm:ss}\t| {level:9}| {message}</level>')
format='<level>{time:YYYY-MM-DD HH:mm:ss}\t| {level:9}| {message}</level>')

from tinypng_unlimited.tiny_img import TinyImg
from tinypng_unlimited.key_manager import KeyManager
2 changes: 1 addition & 1 deletion tinypng_unlimited/key_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def store_key(cls):
def get_api_count(s, key):
url = 'https://api.tinify.com/shrink'
retry = 0
logger.info('正在获取密钥可用性信息...', key)
logger.info('正在获取密钥可用性信息... : {}', key)
while True:
try:
res = s.post(url, auth=('api', key))
Expand Down

0 comments on commit f9a4485

Please sign in to comment.