Created
July 17, 2018 00:38
-
-
Save catichenor/ac526e92e077f619e6bd25e6eaf83664 to your computer and use it in GitHub Desktop.
Apple Calendar Meetings to Markdown
This file contains 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
# To pass in the correct input, you need to use Automator on macOS. | |
# First, add in the "Find Calendar Events" Action and set it to find events where "Date starting" "is today". | |
# Then, pass that to the "Event Summary" Action. | |
# Finally, add a "Run Shell Script" Action and paste the following into it. | |
import sys | |
import re | |
cal_array = [] | |
for i in sys.argv[1:]: | |
cal_array.append(i) | |
cal_array = cal_array[0].splitlines() # Workaround for all lines being passed as one argument. | |
event_indices = [x[0] for x in enumerate(cal_array) if x[1].startswith('Summary')] | |
event_indices.append(len(cal_array)) | |
for i in event_indices[1:-1]: | |
event_indices.append(i-2) | |
event_range_list = sorted(event_indices) | |
separated_events = [] | |
for j in range(0, len(event_indices), 2): | |
separated_events.append(cal_array[event_range_list[j]:event_range_list[j+1]]) | |
event_dict = [] | |
for this_event in separated_events: | |
event_entry = {} | |
for line in this_event: | |
line = line.strip() | |
if line.startswith('Summary:\t'): | |
event_entry['title'] = line.split('\t')[1] | |
if line.startswith('Time:\t'): | |
event_entry['times'] = re.sub(r':00 .M', '', line.split('\t')[1]) | |
if line.startswith('Location:\t'): | |
event_entry['location'] = line.split('\t')[1] | |
if line.startswith('Notes:\t'): | |
event_entry['notes'] = line.split('\t')[1] | |
event_dict.append(event_entry) | |
# At this point we could export out to JSON, but instead we're outputting plain text/Markdown. | |
for this_event in event_dict: | |
if 'title' in this_event: | |
print('### {} Meeting\n'.format(this_event['title'])) | |
if 'times' in this_event: | |
print('* Time: {}'.format(this_event['times'])) | |
if 'location' in this_event: | |
print('* Location: {}'.format(this_event['location'])) | |
if 'notes' in this_event: | |
print('* Invite Notes: {}'.format(this_event['notes'])) | |
print('* Notes:\n - \n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment