download-melbourne-pedestrians.py 763 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
"""
Might be a useful script for some groups to adapt, since most datasets are split
across many different files.
"""

from pathlib import Path
from urllib.request import urlretrieve

import pandas as pd

11
data_url = "https://compedv2api.herokuapp.com/api/bydatecsv/"
12
download_dir = Path(__file__).parent.joinpath("data")
13
download_dates = pd.date_range(start="2020-03-01", end="2020-03-08", freq="D")
14
15
16
17
18
19
20
21
22
23

download_dir.mkdir(exist_ok=True)

for date in download_dates:
    downloaded_file_path = download_dir.joinpath(date.strftime("%Y-%m-%d") + ".csv")
    if downloaded_file_path.exists():
        print("Already loaded:    ", date)
    else:
        urlretrieve(data_url + date.strftime("%d-%m-%Y"), downloaded_file_path)
        print("Download complete: ", date)