From a2d324fb0756a295360535e8037426ddbcbbef0b Mon Sep 17 00:00:00 2001 From: mol Date: Wed, 6 Sep 2023 10:13:57 +0800 Subject: [PATCH] fix: temp --- README.md | 6 ++++++ handlers/pixiv/file.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index d2c1bba..a1582a3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # 更新笔记 +## v1.2.1 + +_Bug fixes_ + +- 修复没有 temp 文件夹的 bug + ## v1.2.0 _Bug fixes_ diff --git a/handlers/pixiv/file.py b/handlers/pixiv/file.py index 7a9a02b..4214071 100644 --- a/handlers/pixiv/file.py +++ b/handlers/pixiv/file.py @@ -3,6 +3,7 @@ import shutil def save_file(name, data): temp_path = os.path.join(os.path.dirname(__file__), 'temp') + check_dir(temp_path) with open(os.path.join(temp_path, name), 'wb') as code: code.write(data) @@ -15,6 +16,7 @@ def remove_file(path): def clear_dir(): temp_path = os.path.join(os.path.dirname(__file__), 'temp') + check_dir(temp_path) flag = True for files in os.listdir(temp_path): path = os.path.join(temp_path, files) @@ -26,4 +28,9 @@ def clear_dir(): print('Info: temp dir is cleared') +def check_dir(path): + is_exists = os.path.exists(path) + if not(is_exists): + os.mkdir(path.encode('utf-8')) + return \ No newline at end of file