Browse Source

Fix downloading of new simfiles, oops

main
fluffy 7 months ago
parent
commit
61153e6b11
1 changed files with 8 additions and 7 deletions
  1. +8
    -7
      zenius.py

+ 8
- 7
zenius.py View File

@@ -9,6 +9,7 @@ import zipfile
from urllib.request import urlretrieve

import requests
import requests.exceptions
from bs4 import BeautifulSoup


@@ -30,7 +31,7 @@ def parse_args(*args):
return parser.parse_args(*args)


def retrieve(url, filename, save_headers=None, extract=True, **kwargs):
def retrieve(url, filename, save_headers=None, extract=None, **kwargs):
print(f'Downloading {url} -> {filename}')
try:
req = requests.get(url, **kwargs, stream=True)
@@ -41,10 +42,9 @@ def retrieve(url, filename, save_headers=None, extract=True, **kwargs):

if extract:
with zipfile.ZipFile(filename, 'r') as zip:
songdir = f'songs/{groupname}'
print(f'Extracting into {songdir}')
os.makedirs(songdir, exist_ok=True)
zip.extractall(songdir)
print(f'Extracting into {extract}')
os.makedirs(extract, exist_ok=True)
zip.extractall(extract)

if save_headers:
pickle.dump(req.headers, open(save_headers, 'wb'))
@@ -52,7 +52,7 @@ def retrieve(url, filename, save_headers=None, extract=True, **kwargs):
print("Not modified")
else:
print(f"Error: {req.status_code} {req.text}")
except requests.BaseHTTPError as e:
except requests.exceptions.BaseHTTPError as e:
print(f'Error downloading: {e.msg}')
except zipfile.BadZipFile:
print(f'Not a zip file: {filename}')
@@ -131,7 +131,8 @@ def mirror(cat_url, args):
headers = f'zips/{sim_id}.headers'
req_headers = load_prev_headers(filename, headers)

retrieve(url, filename, headers=req_headers, save_headers=headers)
retrieve(url, filename, extract=f'songs/{groupname}',
headers=req_headers, save_headers=headers)

for groupname, group_url in group_urls.items():
page = get_page(group_url)


Loading…
Cancel
Save