import sys
import requests
from ics import Calendar
import arrow
import locale

if len(sys.argv) != 2:
	print("Usage: python3 {} <ICS_URL>".format(sys.argv[0]))

url = sys.argv[1]

c = Calendar(requests.get(url).text)

locale.setlocale(locale.LC_TIME, locale.normalize("de_DE.UTF-8"))

print("_model: page")
print("---")
print("title: Termine")
print("---")
print("body:")
print("")
for event in list(c.timeline.start_after(arrow.now())):
	print("* <div>{}</div>&nbsp;".format(event.name))
	print("  * <div>{}</div>&nbsp;".format(event.begin.strftime("%a. %-d. %B %Y")))
	print("  * <div>{}</div>&nbsp;".format(event.begin.strftime("%-H:%M") if not event.all_day else "&nbsp;"))
	print("  * <div>{}</div>&nbsp;".format(event.location if event.location != None else "&nbsp;"))
print("")
print("---")
print("_template: page.html")
print("")
print("")