aboutsummaryrefslogtreecommitdiff
path: root/datasets/iceland_tourism/get_iceland_tourism.py
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-08-17 20:56:12 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-08-17 20:56:12 +0100
commit38800a8e4ce2328548a10ea31062089900385075 (patch)
tree53259b8ed39a6e9d9b39cb894a2e45780c666f42 /datasets/iceland_tourism/get_iceland_tourism.py
parentUse read_table instead of read_csv (diff)
parentAdd retries to all download scripts (diff)
downloadTCPD-38800a8e4ce2328548a10ea31062089900385075.tar.gz
TCPD-38800a8e4ce2328548a10ea31062089900385075.zip
Merge branch 'bugfix/measles_download' into master
Diffstat (limited to 'datasets/iceland_tourism/get_iceland_tourism.py')
-rw-r--r--datasets/iceland_tourism/get_iceland_tourism.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/datasets/iceland_tourism/get_iceland_tourism.py b/datasets/iceland_tourism/get_iceland_tourism.py
index 752f07d..b9c8347 100644
--- a/datasets/iceland_tourism/get_iceland_tourism.py
+++ b/datasets/iceland_tourism/get_iceland_tourism.py
@@ -17,9 +17,12 @@ import hashlib
import json
import os
import xlrd
+import sys
+import time
from functools import wraps
from urllib.request import urlretrieve
+from urllib.error import URLError
XLSX_URL = "https://web.archive.org/web/20191121170223if_/https://www.ferdamalastofa.is/static/files/ferdamalastofa/Frettamyndir/2019/nov/visitors-to-iceland-2002-2019-oct.xlsx"
@@ -84,7 +87,20 @@ def validate(checksum):
@validate(MD5_XLSX)
def download_xlsx(target_path=None):
- urlretrieve(XLSX_URL, target_path)
+ count = 0
+ while count < 5:
+ count += 1
+ try:
+ urlretrieve(XLSX_URL, target_path)
+ return
+ except URLError as err:
+ print(
+ "Error occurred (%r) when trying to download xlsx. Retrying in 5 seconds"
+ % err,
+ sys.stderr,
+ )
+ time.sleep(5)
+
def format_ym(year, month):