Add rudimentary error reporting.
This commit is contained in:
parent
3e15c50e22
commit
a2bc995885
12
macli.py
12
macli.py
@ -59,6 +59,7 @@ def get_extension(path):
|
||||
|
||||
|
||||
def request(url):
|
||||
print("> {}".format(url))
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=None,
|
||||
@ -69,6 +70,10 @@ def request(url):
|
||||
return urllib.request.urlopen(req)
|
||||
|
||||
|
||||
def show_error(e):
|
||||
print("\x1b[41;37m{}\x1b[0m")
|
||||
|
||||
|
||||
def archive(content, base_url, selector, directory, attribute):
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
for part in content.find_all(**selector):
|
||||
@ -84,7 +89,12 @@ def archive(content, base_url, selector, directory, attribute):
|
||||
|
||||
path = os.path.join(directory, name)
|
||||
if not os.path.exists(path):
|
||||
content = request(href).read()
|
||||
try:
|
||||
content = request(href).read()
|
||||
except Exception as e:
|
||||
show_error(e)
|
||||
continue
|
||||
|
||||
with open(path, 'wb') as f:
|
||||
f.write(content)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user