Skip to content

Commit 33a1730

Browse files
committed
Download weather file if not present
1 parent 4b7a082 commit 33a1730

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

example/modelchain_example.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
import os
1717
import pandas as pd
18+
import requests
1819

1920
try:
2021
from matplotlib import pyplot as plt
@@ -65,11 +66,16 @@ def get_weather_data(filename='weather.csv', **kwargs):
6566
"""
6667

6768
if "datapath" not in kwargs:
68-
kwargs["datapath"] = os.path.join(
69-
os.path.split(os.path.dirname(__file__))[0], "example"
70-
)
69+
kwargs["datapath"] = os.path.dirname(__file__)
70+
7171
file = os.path.join(kwargs["datapath"], filename)
7272

73+
if not os.path.isfile(file):
74+
logging.debug("Download weather data for example.")
75+
req = requests.get("https://osf.io/59bqn/download")
76+
with open(file, "wb") as fout:
77+
fout.write(req.content)
78+
7379
# read csv file
7480
weather_df = pd.read_csv(
7581
file,

0 commit comments

Comments
 (0)