aboutsummaryrefslogtreecommitdiff
path: root/datasets/bitcoin/get_bitcoin.py
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-08-17 20:44:42 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-08-17 20:44:42 +0100
commit9480e00023b1315609000cf256c59425e9efdccd (patch)
tree53259b8ed39a6e9d9b39cb894a2e45780c666f42 /datasets/bitcoin/get_bitcoin.py
parentAdd retries to the get_measles script (diff)
downloadTCPD-9480e00023b1315609000cf256c59425e9efdccd.tar.gz
TCPD-9480e00023b1315609000cf256c59425e9efdccd.zip
Add retries to all download scripts
Diffstat (limited to 'datasets/bitcoin/get_bitcoin.py')
-rw-r--r--datasets/bitcoin/get_bitcoin.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/datasets/bitcoin/get_bitcoin.py b/datasets/bitcoin/get_bitcoin.py
index e0b2917..281b093 100644
--- a/datasets/bitcoin/get_bitcoin.py
+++ b/datasets/bitcoin/get_bitcoin.py
@@ -13,13 +13,16 @@ Copyright: 2019, The Alan Turing Institute
"""
import argparse
+import clevercsv
import hashlib
import json
import os
-import clevercsv
+import sys
+import time
from functools import wraps
from urllib.request import urlretrieve
+from urllib.error import URLError
CSV_URL = "https://web.archive.org/web/20191114131838if_/https://api.blockchain.info/charts/market-price?timespan=all&format=csv"
@@ -70,7 +73,19 @@ def validate(checksum):
@validate(MD5_CSV)
def get_market_price(target_path=None):
- urlretrieve(CSV_URL, target_path)
+ count = 0
+ while count < 5:
+ count += 1
+ try:
+ urlretrieve(CSV_URL, target_path)
+ return
+ except URLError as err:
+ print(
+ "Error occurred (%r) when trying to download csv. Retrying in 5 seconds"
+ % err,
+ sys.stderr,
+ )
+ time.sleep(5)
@validate(MD5_JSON)