Skip to content

Commit

Permalink
Add possibility to generate extra dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ebousse committed Nov 6, 2023
1 parent bb183a6 commit 5fd152d
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions seminar/generate_mondays.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ def find_next_monday(date: datetime.date):
return on_day(date, 0)


def generate_event_file(date: datetime.date, speaker: str, counter: int):
next_monday: datetime.date = find_next_monday(date)
file_name = str(next_monday) + "-talk" + str(counter) + ".md"
output_file: Path = output_dir / file_name
output_file.write_text(template.substitute(speaker=speaker))
print("Created " + str(output_file))


############
# Input data
############
start_date: datetime.date = datetime.date(2023, 11, 14)
output_dir: Path = Path("./seminar/2324/_posts")
output_dir: Path = Path("./seminar/test/_posts")
speakers: list[str] = [
"Gerson Sunyé",
"Massimo Tisi",
Expand All @@ -41,28 +49,30 @@ def find_next_monday(date: datetime.date):
"James Miranda",
]
random.shuffle(speakers)
extra_dates: int = 5

############
# Preparations
############
output_dir.mkdir(parents=True, exist_ok=True)
example_file: Path = Path("./seminar/talk_template.md")
if not example_file.exists():
raise "Missing example file at location " + str(example_file)
raise Exception("Missing example file at location " + str(example_file))

template: Template = Template(example_file.read_text())

############
# Loop
############
current_date = start_date + datetime.timedelta(days=1)
current_date = find_next_monday(start_date + datetime.timedelta(days=1))
counter: int = 1

for speaker in speakers:
next_monday: datetime.date = find_next_monday(current_date)
file_name = str(next_monday) + "-talk" + str(counter) + ".md"
generate_event_file(current_date, speaker, counter)
counter = counter + 1
output_file: Path = output_dir / file_name
output_file.write_text(template.substitute(speaker=speaker))
print("Created " + str(output_file))
current_date = next_monday + datetime.timedelta(days=1)
current_date = find_next_monday(current_date + datetime.timedelta(days=1))

for extra in range(0, extra_dates):
generate_event_file(current_date, "TBA", counter)
counter = counter + 1
current_date = find_next_monday(current_date + datetime.timedelta(days=1))

0 comments on commit 5fd152d

Please sign in to comment.