Skip to content

Instantly share code, notes, and snippets.

@jkoelker
Created July 19, 2017 03:34
Show Gist options
  • Save jkoelker/bf3cde992946ecf10ffae2ccb63815e3 to your computer and use it in GitHub Desktop.
Save jkoelker/bf3cde992946ecf10ffae2ccb63815e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import argparse
import itertools
import maya
import icalendar
SEQUENCE = ('Total Body Cardio Fix',
'Upper Fix',
'Lower Fix',
'Pilates Fix',
'Cardio Fix',
'Dirty 30',
'Yoga Fix')
DOUBLES = ('Pilates Fix',
'Cardio Fix',
'10min Fix for Abs',
'Total Body Cardio Fix',
'Upper Fix',
'Pilates Fix',
None)
def make_event(when, summary):
event = icalendar.Event()
event.add('summary', summary)
event.add('dtstart', when.datetime().date())
return event
def get_schedule(start='now', doubles=False):
when = maya.when(start)
cal = icalendar.Calendar()
cal.add('prodid', '-//21 Day Fix//EN')
cal.add('version', '2.0')
for workout in itertools.chain(zip(SEQUENCE, itertools.repeat(None)),
zip(SEQUENCE, itertools.repeat(None)),
zip(SEQUENCE, DOUBLES)):
cal.add_component(make_event(when, workout[0]))
if doubles and workout[1]:
cal.add_component(make_event(when, workout[1]))
when = when.add(days=1)
return cal
def main():
description = '21 Day Fix Calendar Generator'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-d', '--doubles', action='store_true',
help='Generate Doubles routine')
parser.add_argument('-o', '--outfile',
default='21day-fix.ics',
help='Filename to generate')
parser.add_argument('start', nargs='?', default='now',
help='Date to start (default: now')
args, _ = parser.parse_known_args()
schedule = get_schedule(args.start, args.doubles)
with open(args.outfile, 'wb') as f:
f.write(schedule.to_ical())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment