trhlina-calendar/trhkalendar.py

34 lines
958 B
Python

from ics import Calendar, Event
import requests
import os
import re
PUBLIC_ICAL_URL = os.environ.get('PUBLIC_ICAL_URL')
PRIVATE_ICAL_URL = os.environ.get('PRIVATE_ICAL_URL')
ical_headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'}
public_cal_raw = requests.get(PUBLIC_ICAL_URL, headers=ical_headers).text
private_cal_raw = requests.get(PRIVATE_ICAL_URL, headers=ical_headers).text
# print(public_cal_raw)
pub_cal = Calendar(public_cal_raw)
priv_cal = Calendar(private_cal_raw)
final_cal = Calendar()
for event in priv_cal.events:
event.url = None
#event.uid = None
event.description = None
event.name = "Closed event - not for public"
final_cal.events.add(event)
for event in pub_cal.events:
event.url = None
event.description = event.description.split("\n",2)[2] # Remove forum URL from description
final_cal.events.add(event)
print(final_cal.serialize())