Last active
October 23, 2024 22:14
-
-
Save dumbmatter/d424ae0d77f0e2129b02a39ec21adf2f to your computer and use it in GitHub Desktop.
Custom schedule maker for ZenGM games
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
TRADE_DEADLINE_WEEK = 9 | |
with open("schedule.csv") as f: | |
reader = csv.reader(f) | |
header = next(reader) | |
# One row for each team, one column for each week | |
schedule = list(reader) | |
with open("export.json", "r", encoding="utf-8-sig") as file: | |
export = json.load(file) | |
teams = export["teams"] | |
teamsByAbbrev = {} | |
for t in teams: | |
teamsByAbbrev[t["abbrev"]] = t["tid"] | |
numWeeks = len(header) - 1 | |
scheduleList = [] | |
hasErrors = False | |
for i in range(1, numWeeks + 1): | |
abbrevsThisWeek = set() | |
if i == TRADE_DEADLINE_WEEK: | |
tradeDeadline = { | |
"day": i, | |
"homeTid": -3, | |
"awayTid": -3, | |
} | |
scheduleList.append(tradeDeadline) | |
for s in schedule: | |
if s[i] == "BYE": | |
continue | |
else: | |
# Ignore @ games cause they are duplicates | |
if "@" in s[i]: | |
continue | |
if s[0] not in teamsByAbbrev: | |
print(f'Invalid abbrev "{s[0]}" in the first column') | |
hasErrors = True | |
continue | |
if s[i] not in teamsByAbbrev: | |
print(f'Invalid abbrev "{s[i]}" in week {i} for row {s[0]}') | |
hasErrors = True | |
continue | |
for abbrev in [s[0], s[i]]: | |
if abbrev in abbrevsThisWeek: | |
print(f'Two games for {abbrev} in week {i}') | |
hasErrors = True | |
abbrevsThisWeek.add(abbrev) | |
newGame = { | |
"day": i, | |
"homeTid": teamsByAbbrev[s[0]], | |
"awayTid": teamsByAbbrev[s[i]], | |
} | |
scheduleList.append(newGame) | |
if hasErrors: | |
print("Please fix the above errors and try again") | |
else: | |
export["schedule"] = scheduleList | |
with open("newExport.json", "w") as file: | |
json.dump(export, file) | |
print("Complete! Schedule inserted into newExport.json.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://reddit.com/r/Football_GM/comments/q0wd1g/create_schedules_from_spreadsheets/ for details
This version will check for various things (invalid abbrevs, multiple games for the same team in the same day) and show you any errors it finds.
Also any of the away games (starting with @) are ignored, since that is duplicate info (there is a corresponding home game in the other team's row). So you can just leave those out if you want.