trhlina-calendar/trhkalendar.py
2023-05-29 19:41:28 +02:00

42 lines
1.1 KiB
Python

#from flask import Flask, render_template, request, redirect
from ics import Calendar, Event
import requests
#from dotenv import load_dotenv
import os
import re
#load_dotenv()
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'}
print("URL: ")
print(PUBLIC_ICAL_URL)
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())