Compare commits

...

2 Commits

2 changed files with 27 additions and 2 deletions

View File

@@ -123,6 +123,16 @@ def download_and_extract(download_url, extract_dir='.', password=None):
# 确保解压目录存在 # 确保解压目录存在
os.makedirs(extract_dir, exist_ok=True) 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文件到临时目录 # 下载ZIP文件到临时目录
with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as tmp: with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as tmp:
zip_path = tmp.name zip_path = tmp.name
@@ -167,6 +177,21 @@ def download_and_extract(download_url, extract_dir='.', password=None):
raise e raise e
print(f"Download and extraction completed successfully.") 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 return True
except (requests.exceptions.RequestException, zipfile.BadZipFile, IOError, Exception) as e: except (requests.exceptions.RequestException, zipfile.BadZipFile, IOError, Exception) as e:
raise Exception(f"Failed to download and extract: {str(e)}") raise Exception(f"Failed to download and extract: {str(e)}")

View File

@@ -3,8 +3,8 @@ name = "myscripts"
version = "0.1.0" version = "0.1.0"
description = "Add your description here" description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.13" requires-python = ">=3.10"
dependencies = ["requests"] dependencies = ["requests"]
[project.scripts] [project.scripts]
working_tool = "myscripts.working_tool:main" working_tool = "myscripts.working_tool:main"