Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Pull years out of ICS file #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ICS files
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
49 changes: 49 additions & 0 deletions ics_info.py
Original file line number Diff line number Diff line change
@@ -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))