diff --git a/rank_progress.py b/rank_progress.py --- a/rank_progress.py +++ b/rank_progress.py @@ -1,11 +1,13 @@ +import sys import re import io from itertools import groupby from datetime import datetime import shutil import argparse +from zipfile import ZipFile import urllib.request -from zipfile import ZipFile +from urllib.error import URLError class Record: @@ -149,10 +151,18 @@ if __name__ == "__main__": else: url = "https://europeangodatabase.eu/EGD/EGD_2_0/downloads/hisgor.zip" print("Downloading data from {} ...".format(url)) - with urllib.request.urlopen(url) as f: - compressed_data = f.read() - with ZipFile(io.BytesIO(compressed_data)) as g: - s = g.read("all.hst").decode("utf-8") + try: + with urllib.request.urlopen(url) as f: + compressed_data = f.read() + with ZipFile(io.BytesIO(compressed_data)) as g: + s = g.read("all.hst").decode("utf-8") + except URLError as e: + print( + "* Failed to connect to the server. " + "You can try again later or download {} and run the program with the -f parameter.\n" + "The error message:\n{}".format(url, e) + ) + sys.exit(1) print("Processing...") main(s, since, to, args)