Changeset - f16ea61e1ace
[Not reviewed]
default
0 1 0
Laman - 3 years ago 2021-10-24 15:50:41

handled a URLError
1 file changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rank_progress.py
Show inline comments
 
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:
 
	def __init__(self, tokens, source):
 
		self.source = source
 

	
 
@@ -146,15 +148,23 @@ if __name__ == "__main__":
 
		print("Reading {} ...".format(args.file))
 
		with ZipFile(args.file) as f:
 
			s = f.read("all.hst").decode("utf-8")
 
	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)
 

	
 
	print("Done.")
0 comments (0 inline, 0 general)