Compare commits
2 Commits
77a8f51e5d
...
efb1b7a893
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efb1b7a893 | ||
|
|
d3b2f26f74 |
@@ -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)}")
|
||||
|
||||
@@ -3,7 +3,7 @@ name = "myscripts"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = ["requests"]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
Reference in New Issue
Block a user