diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..636de8f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ICS files diff --git a/README.md b/README.md index 47ad60e..a0e17cb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ +This is a fork of https://github.com/druths/icssplitter + +# Getting dates present in an ICS file +You may need to break apart an ICS file so that you can upload it to a cloud-based system, but you may not know which years you have calendar events for. To solve this, I modified icssplitter and added ics_info.py. This will split out a list of years that you can then feed into icssplitter. + +Basic usage for this tool is: + + python ics_info.py my_big_file.ics. + +In case the original project gets removed, here is the README for icssplitter. + # Let's split those ICS files... ics files allow us to move calendar events between calendaring systems (e.g., Google and Exchange). The problem is that they get big... and cloud-based diff --git a/ics_info.py b/ics_info.py new file mode 100644 index 0000000..75c1b61 --- /dev/null +++ b/ics_info.py @@ -0,0 +1,49 @@ +""" +A handy script for extracting all event years from an ICS file. +Works well for determining what values to pass to https://github.com/druths/icssplitter/ + +@author Dan Getz (@quizwedge) +""" + +import argparse +import re + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('input_file', help='the input ICS file') + + args = parser.parse_args() + + print(f'Extracting years from {args.input_file}') + + created_pattern = re.compile('^DTSTART') + + in_fname = args.input_file + + infh = open(in_fname, 'r') + + # parsing constants + BEGIN_EVENT = 'BEGIN:VEVENT' + END_EVENT = 'END:VEVENT' + + in_preamble = True + in_event = False + events = set() + + for line in infh: + if in_preamble and line.startswith(BEGIN_EVENT): + in_preamble = False + + if not in_preamble: + if line.startswith(BEGIN_EVENT): + in_event = True + + if in_event: + if created_pattern.match(line): + last_value = line.split(':')[-1][:4] + events.add(last_value) + + if line.startswith(END_EVENT): + in_event = False + + print(sorted(events)) \ No newline at end of file