Skip to content

Instantly share code, notes, and snippets.

@bklaas
Created March 16, 2024 02:26
Show Gist options
  • Save bklaas/b3f091de911ca45d0b38b0ea72dab99e to your computer and use it in GitHub Desktop.
Save bklaas/b3f091de911ca45d0b38b0ea72dab99e to your computer and use it in GitHub Desktop.
Python script to process copypasta from leaguelobster's round robin generator
from pprint import pprint
class Week:
def __init__(self, week):
self.week = week
def __str__(self):
matches = []
for t in self.week:
matches.append(f"{t[0]}v{t[1]}")
return ",".join(matches)
def get_byes(week):
byes = []
for t in range(1,25):
if str(t) not in week:
byes.append(t)
return byes
matchups = []
byes = []
with open("schedule.txt", "r") as f:
week = []
for line in f:
l = line.strip()
if l.startswith('Week'):
if len(week):
matchups.append(week)
byes.append(get_byes(week))
week = []
elif not l.startswith('V'):
week.append(l.replace('Team ', ''))
matchups.append(week)
byes.append(get_byes(week))
# Convert the list of values into a list of tuples
for values in matchups:
tuples_list = [(values[i], values[i+1]) for i in range(0, len(values), 2)]
print(Week(tuples_list))
def print_schedule(matchups, byes):
output = []
# header
times = ['4:30', '4:40', '4:50', '5:00', '5:10', '5:20', '5:30', '5:40', '5:50']
line = "Week/Tee time,"
for time in times:
for x in range(0, 2):
line += f"{time},"
for bye in range(1,7):
line += "bye,"
output.append(line.strip(','))
# matches
i = 1
for week in zip(matchups, byes):
line = f"{i},"
for match in week[0]:
line += f"{match},"
# byes
for bye in week[1]:
line += f"{bye},"
output.append(line.strip(','))
i += 1
with open("schedule.csv", "w") as f:
for l in output:
f.write(f"{l}\n")
print_schedule(matchups, byes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment