Add version to download folder

This commit is contained in:
Isaac Shoebottom 2024-07-31 19:34:39 -03:00
parent 29e3a425a3
commit c533330f1a
2 changed files with 8 additions and 0 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
downloads/ downloads/
# Fallback in case files are not in the downloads folder # Fallback in case files are not in the downloads folder
*.7z *.7z
VERSION
# Ignore the build folder # Ignore the build folder
__pycache__/ __pycache__/
# Ignore environment files # Ignore environment files

View File

@ -86,10 +86,16 @@ def download_file(edit):
opener = build_opener() opener = build_opener()
print("Download link: ", download_link) print("Download link: ", download_link)
opener.addheaders = [("apikey", API_KEY), ("User-Agent", "Mozilla/5.0")] opener.addheaders = [("apikey", API_KEY), ("User-Agent", "Mozilla/5.0")]
# Create directories if they don't exist
filename = f"{edit['name']} {edit['version']}.7z" filename = f"{edit['name']} {edit['version']}.7z"
path = f"./downloads/{edit['name']}/{filename}" path = f"./downloads/{edit['name']}/{filename}"
if not os.path.exists(os.path.dirname(path)): if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path)) os.makedirs(os.path.dirname(path))
# Write VERSION file
with open(f"./downloads/{edit['name']}/VERSION", "w") as version_file:
version_file.write(edit["version"])
# If file already exists, skip download # If file already exists, skip download
if os.path.exists(path): if os.path.exists(path):
print(f"File {filename} already exists, skipping download...") print(f"File {filename} already exists, skipping download...")
@ -98,6 +104,7 @@ def download_file(edit):
with open(path, "wb") as file: with open(path, "wb") as file:
file.write(response.read()) file.write(response.read())
for edit in xEdits: for edit in xEdits:
print(f"Downloading {edit}...") print(f"Downloading {edit}...")
download_file(xEdits[edit]) download_file(xEdits[edit])