#!/home/ANT.AMAZON.COM/crutem/calendar/bin/python3 # # pip install icalendar # import sys from datetime import datetime from icalendar import Calendar def format_name(address): if not address: return "" email = address.split(":")[1] if "cn" in address.params: return "{} <{}>".format(address.params["cn"], email) return email def format_attendees(attendees): if isinstance(attendees, list): return ", ".join([format_name(a) for a in attendees]) return format_name(attendees) for event in Calendar.from_ical(sys.stdin.read()).walk("vevent"): organizer = format_name(event.get("organizer", "")) if organizer: print(f"Organizer: {organizer}") attendees = format_attendees(event.get("attendee")) if attendees: print(f"Attendees: {attendees}") summary = event.get("summary", "") if summary: print(f"Summary: {summary}") time_from = datetime.strftime( event.get("dtstart").dt, "%a %d %b %Y %H:%M") time_to = datetime.strftime(event.get("dtend").dt, "%H:%M") if time_from: print(f"When: {time_from}-{time_to}") location = event.get("location", "") if location: print(f"Location: {location}") comment = event.get("comment", "") if comment: print(f"Comment: {comment}") description = event.get("description", "") if description: print(f"Description:\n{description}") print("---")