diff --git a/macli.py b/macli.py index 95e5ae8..4a487ef 100644 --- a/macli.py +++ b/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)