forked from NoLog.cz/trhlina-calendar
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from ics import Calendar, Event
|
|
import requests
|
|
import os
|
|
import re
|
|
import arrow
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
pub_cal = Calendar(public_cal_raw)
|
|
priv_cal = Calendar(private_cal_raw)
|
|
|
|
# print(pub_cal)
|
|
|
|
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"
|
|
event.begin = event.begin.shift(hours=+1)
|
|
event.end = event.end.shift(hours=+1)
|
|
final_cal.events.add(event)
|
|
|
|
|
|
for event in pub_cal.events:
|
|
event.url = None
|
|
event.begin = event.begin.shift(hours=+1)
|
|
event.end = event.end.shift(hours=+1)
|
|
event.description = event.description.split("\n",2)[2] # Remove forum URL from description
|
|
final_cal.events.add(event)
|
|
|
|
raw_cal = final_cal.serialize()
|
|
raw_cal = raw_cal.replace('DTSTART:', 'DTSTART;TZID=Europe/Prague:')
|
|
raw_cal = raw_cal.replace('DTEND:', 'DTEND;TZID=Europe/Prague:')
|
|
raw_cal = raw_cal.replace('00Z', '00')
|
|
|
|
print(raw_cal)
|