Created
November 20, 2024 08:04
-
-
Save rrmichel/8d9c38829f8c65f1e100b133ab127bd3 to your computer and use it in GitHub Desktop.
mutt ics viewer
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
| #!/bin/env python | |
| import icalendar | |
| import argparse | |
| import pathlib | |
| from colorama import init | |
| from termcolor import colored | |
| from pathlib import Path | |
| # colorama | |
| init() | |
| # argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--ics","-i", required=True, help="path to ics file") | |
| parser.add_argument("--debug","-d", action="store_true") | |
| args = parser.parse_args() | |
| ics_path = Path(args.ics) | |
| def pt(t, color="black"): | |
| title = colored(t, color, attrs=["bold", "underline"]) | |
| return title | |
| def debug(msg): | |
| if args.debug: | |
| print(pt("DEBUG:", "red") + " %s" % msg) | |
| debug("Proessing file: %s" % ics_path) | |
| try: | |
| with ics_path.open() as f: | |
| calendar = icalendar.Calendar.from_ical(f.read()) | |
| for event in calendar.walk('VEVENT'): | |
| print("%s: %s" % (pt("Organizer"),event.get("organizer"))) | |
| print("%s: %s" % (pt("Location"),event.get("location"))) | |
| print("%s: %s" % (pt("Start"),event.decoded("DTSTART"))) | |
| print("%s: %s" % (pt("End"),event.decoded("DTEND"))) | |
| print("%s:\n%s" % (pt("Description"),event.get("DESCRIPTION"))) | |
| except ValueError: | |
| print("Abort - ics file ok?") | |
| except: | |
| print("Unknown error occurred. Path ok?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment