From a2bc995885f679a6e85b23bf65ce55505930ba1b Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Wed, 5 Jul 2017 00:47:03 +0200 Subject: [PATCH] Add rudimentary error reporting. --- macli.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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)