Skip to content

Commit 7167ad7

Browse files
committed
support lists
1 parent 02c7278 commit 7167ad7

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ It is a simple helper for cases when one needs to download data in systems like
66
```python
77

88
from data import get_data
9-
get_data(url="", filename="LiFePO4_supercell.cif", folder="data")
9+
get_data(url="https://raw.githubusercontent.com/ddmms/data-tutorials/main/data/LiFePO4_supercell.cif", filename="LiFePO4_supercell.cif", folder="data")
1010

1111

data_tutorials/data.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77
from urllib.request import urlretrieve
88
from pathlib import Path
99

10-
default_url = "https://raw.githubusercontent.com/imagdau/Tutorials/main/data/"
11-
12-
def get_data(url: str=default_url, filename: str| list[str] = "", folder: str="data") -> None:
13-
p = Path(folder)
14-
p.mkdir(parents=True, exist_ok=True)
15-
save_file = p/filename
16-
path, headers = urlretrieve(url+filename, save_file)
10+
default_url = "https://raw.githubusercontent.com/ddmms/data-tutorials/main/data/"
11+
def download_file(url: str, filename:str, dest: Path) -> None:
12+
save_file = dest/filename
13+
path, headers = urlretrieve(url, dest)
1714
if path.exists():
1815
print(f"saved in {save_file}")
1916
else:
2017
print(f"{save_file} could not be downloaded, check url.")
18+
19+
def get_data(url: str=default_url, filename: str| list[str] = "", folder: str="data") -> None:
20+
p = Path(folder)
21+
p.mkdir(parents=True, exist_ok=True)
22+
if isinstance(filename,str):
23+
download_file(url,filename,p)
24+
elif isinstance(filename, list):
25+
for f in filename:
26+
download_file(url,f,p)

0 commit comments

Comments
 (0)