Skip to content

Commit cf16175

Browse files
authored
Merge pull request #26 from openmc-data-storage/develop
retrying download on fail
2 parents 31e9ac0 + ab03842 commit cf16175

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

openmc_data_downloader/utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from typing import List, Optional, Union
66
from urllib.parse import urlparse
77
from urllib.request import urlopen
8-
8+
from urllib.error import HTTPError
99
import pandas as pd
10+
from retry import retry
1011

1112
from openmc_data_downloader import (
1213
ISOTOPE_OPTIONS,
@@ -48,7 +49,7 @@ def expand_materials_to_isotopes(materials: list):
4849
msg = (
4950
"import openmc failed. openmc python package could not be found "
5051
"and was not imported, the expand_materials_to_isotopes "
51-
"opperation can not be performed ithout openmc"
52+
"opperation can not be performed without openmc"
5253
)
5354
raise ImportError(msg)
5455

@@ -95,7 +96,7 @@ def expand_materials_to_sabs(materials: list):
9596
msg = (
9697
"import openmc failed. openmc python package could not be found "
9798
"and was not imported, the expand_materials_to_sabs "
98-
"opperation can not be performed ithout openmc"
99+
"opperation can not be performed without openmc"
99100
)
100101
raise ImportError(msg)
101102

@@ -231,6 +232,13 @@ def download_single_file(
231232
print("Skipping {}, already downloaded".format(local_path))
232233
return local_path
233234

235+
local_path = download_url_in_chuncks(url, local_path)
236+
237+
return local_path
238+
239+
240+
@retry(HTTPError, tries=3)
241+
def download_url_in_chuncks(url, local_path):
234242
with urlopen(url) as response:
235243

236244
# Copy file to disk in chunks
@@ -336,7 +344,7 @@ def identify_sab_to_download(
336344
print("Searching libraries with the following priority", priority_dict)
337345

338346
# Tried to removed this dict to dataframe conversion out of the function
339-
# and into the initilisation of the package but this resultied in
347+
# and into the initialization of the package but this resultied in
340348
# a SettingwithCopyWarning which can be fixed and understood here
341349
# https://www.dataquest.io/blog/settingwithcopywarning/
342350
sab_info_df = pd.DataFrame.from_dict(sab_info)
@@ -410,7 +418,7 @@ def identify_isotopes_to_download(
410418
print("Searching libraries with the following priority", priority_dict)
411419

412420
# Tried to removed this dict to dataframe conversion out of the function
413-
# and into the initilisation of the package but this resultied in
421+
# and into the initialization of the package but this resultied in
414422
# a SettingwithCopyWarning which can be fixed and understood here
415423
# https://www.dataquest.io/blog/settingwithcopywarning/
416424
xs_info_df = pd.DataFrame.from_dict(xs_info)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
pandas
3+
retry
34
# openmc is optional, but not avaialbe via pip

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
tests_require=["pytest-cov", "pytest-runner"],
3939
install_requires=[
4040
"pandas",
41+
"retry",
4142
# 'openmc' is optional for this package but is not available via pip install at the moment
4243
],
4344
)

0 commit comments

Comments
 (0)