diff --git a/myscripts/working_tool.py b/myscripts/working_tool.py index bce5ecb..fff0ea4 100644 --- a/myscripts/working_tool.py +++ b/myscripts/working_tool.py @@ -123,6 +123,16 @@ def download_and_extract(download_url, extract_dir='.', password=None): # 确保解压目录存在 os.makedirs(extract_dir, exist_ok=True) + # 检查是否与最后一次下载的URL相同 + last_upload_file = LAST_UPLOAD_FILE + if os.path.exists(last_upload_file): + with open(last_upload_file, 'r') as f: + last_data = json.load(f) + + if last_data.get('download_url') == download_url: + print(f"URL {download_url} is the same as last download. Skipping download.") + return True + # 下载ZIP文件到临时目录 with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as tmp: zip_path = tmp.name @@ -167,6 +177,21 @@ def download_and_extract(download_url, extract_dir='.', password=None): raise e print(f"Download and extraction completed successfully.") + + # 将下载信息保存到解压目录 + download_info = { + 'download_url': download_url, + 'extract_dir': extract_dir, + 'timestamp': os.path.getmtime(zip_path), + 'encrypted': bool(password), + 'extracted_files': len(os.listdir(extract_dir)) if os.path.exists(extract_dir) else 0 + } + + download_info_file = os.path.join(extract_dir, '.download_info.json') + with open(download_info_file, 'w') as f: + json.dump(download_info, f, indent=2) + + print(f"Download information saved to {download_info_file}") return True except (requests.exceptions.RequestException, zipfile.BadZipFile, IOError, Exception) as e: raise Exception(f"Failed to download and extract: {str(e)}")