# From Football Data Science by Bryan McGuire. Free to use with credit.
# https://www.footballdatascience.co.uk/data
# Downloads the Scottish results and odds files the site's snippets use, straight from football-data.co.uk
# (their files, not this site's). Run it once in an empty folder, then run any article's snippet there.
import os
import time
import urllib.request

SEASONS = [f"{y % 100:02d}{(y + 1) % 100:02d}" for y in range(2000, 2026)]   # 2000/01 to 2025/26
DIVISIONS = ("SC0", "SC1")                                                   # Premiership, Championship

for div in DIVISIONS:
    for season in SEASONS:
        name = f"{div}_{season}.csv"
        if os.path.exists(name):
            continue
        urllib.request.urlretrieve(f"https://www.football-data.co.uk/mmz4281/{season}/{div}.csv", name)
        print("saved", name)
        time.sleep(0.5)                                                      # be polite to their server
print("All", len(DIVISIONS) * len(SEASONS), "files are here.")
