Skip to content

Commit 9f23886

Browse files
committed
Fix filename construction
1 parent 655d4f6 commit 9f23886

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

usafacts/delphi_usafacts/pull.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def fetch(url: str, cache: str) -> pd.DataFrame:
2525
"""
2626
r = requests.get(url)
2727
r.raise_for_status()
28-
filename = os.path.join(
29-
cache,
30-
f"{date.today().strftime('%Y%m%d')}_{url.replace(r'.*/','')}.csv")
28+
datestamp = date.today().strftime('%Y%m%d')
29+
name = url.split('/')[-1].replace('.csv','')
30+
os.makedirs(cache, exist_ok=True)
31+
filename = os.path.join(cache, f"{datestamp}_{name}.csv")
3132
with open(filename, "w") as f:
3233
f.write(r.text)
3334
return pd.read_csv(filename)

0 commit comments

Comments
 (0)