diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-08-17 20:56:12 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-08-17 20:56:12 +0100 |
| commit | 38800a8e4ce2328548a10ea31062089900385075 (patch) | |
| tree | 53259b8ed39a6e9d9b39cb894a2e45780c666f42 /datasets/bitcoin/get_bitcoin.py | |
| parent | Use read_table instead of read_csv (diff) | |
| parent | Add retries to all download scripts (diff) | |
| download | TCPD-38800a8e4ce2328548a10ea31062089900385075.tar.gz TCPD-38800a8e4ce2328548a10ea31062089900385075.zip | |
Merge branch 'bugfix/measles_download' into master
Diffstat (limited to 'datasets/bitcoin/get_bitcoin.py')
| -rw-r--r-- | datasets/bitcoin/get_bitcoin.py | 19 |
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) |
