Created
November 4, 2024 21:18
-
-
Save kevit/6bf8dd7bb6d0a6ec560820fbc2e0d957 to your computer and use it in GitHub Desktop.
ics2vfb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
from icalendar import Calendar, Event, FreeBusy | |
from datetime import datetime | |
import sys | |
def fetch_ics(url): | |
response = requests.get(url) | |
response.raise_for_status() | |
return response.text | |
def create_vfb(ics_content): | |
cal = Calendar.from_ical(ics_content) | |
freebusy = FreeBusy() | |
for component in cal.walk(): | |
if component.name == "VEVENT": | |
start = component.get('dtstart').dt | |
end = component.get('dtend').dt | |
freebusy.add('FREEBUSY', (start, end)) | |
vfb_content = freebusy.to_ical() | |
return vfb_content | |
ics_url = sys.argv[1] | |
if ics_url == "-h": | |
print("Usage: python ical2vfb.py <url>") | |
sys.exit(0) | |
ics_content = fetch_ics(ics_url) | |
vfb_content = create_vfb(ics_content) | |
with open('freebusy.vfb', 'wb') as f: | |
f.write(vfb_content) | |
print("VFB created successfully") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment