Skip to content
Snippets Groups Projects
Unverified Commit 32fce96b authored by Lukas Kluft's avatar Lukas Kluft
Browse files

Add script to convert lecture dates to iCal

parent 322139f1
No related branches found
No related tags found
1 merge request!32Extract lectures dates from Markdown
#!/usr/bin/env python3
import argparse
import markdown2
from bs4 import BeautifulSoup
from icalendar import Calendar, Event
from datetime import datetime
def extract_lecture_dates(markdown_file, output_file):
with open(markdown_file, "r") as file:
html_content = markdown2.markdown(file.read(), extras=["tables"])
cal = Calendar()
cal.add("prodid", "-//md2ical//Generic Software Skills Lectures//EN")
cal.add("version", "2.0")
cal.add("x-wr-calname", "GSS Lectures")
soup = BeautifulSoup(html_content, "html.parser")
for table_entry in soup.findAll("tr")[1:]:
date, title, lecturers = [e.contents[0] for e in table_entry.findAll("td")]
event = Event()
event.add("summary", f"{title} ({lecturers})")
event.add("uid", f"{title}+{lecturers}".replace(" ", "+").replace(",", ""))
event.add("dtstamp", datetime.fromisoformat(f"{date}T1100Z"))
event.add("dtstart", datetime.fromisoformat(f"{date}T1100Z"))
event.add("dtend", datetime.fromisoformat(f"{date}T1300Z"))
event.add("location", "Geomatikum, Room 1536a")
cal.add_component(event)
with open(output_file, "wb") as f:
f.write(cal.to_ical())
def main():
parser = argparse.ArgumentParser(
prog="md2ical",
description="Convert a Markdown calendar table to an iCal calendar.",
)
parser.add_argument("-f", "--filename", required=True)
parser.add_argument("-o", "--output", required=True)
args = parser.parse_args()
extract_lecture_dates(args.filename, args.output)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment