Skip to content

Instantly share code, notes, and snippets.

@kjaymiller
Last active September 10, 2016 19:20
Show Gist options
  • Save kjaymiller/acccde2ff38f2717a6d03f539de427ae to your computer and use it in GitHub Desktop.
Save kjaymiller/acccde2ff38f2717a6d03f539de427ae to your computer and use it in GitHub Desktop.
Make Schedule
"""
Make Schedule converts a list of items into a schedule to repeat on the same day.
I use this to get an idea of when my episodes are airing and to know what promotions to use when.
"""
from datetime import datetime, timedelta
def make_schedule(episodes,
release_day,
date_start=datetime.today(),
interval=7,
repeat=1):
calendar = []
while date_start.weekday() != release_day:
date_start = date_start + timedelta(days=1)
next_date = date_start
for episode in episodes * repeat:
calendar.append((episode.rstrip('\n'), next_date.strftime("%b %d")))
next_date = next_date + timedelta(days=interval)
return calendar
def import_list(filename):
with open(filename) as f:
source = f.readlines()
return source
def export_schedule(filename, schedule):
with open(filename, 'w+') as f:
for event in schedule:
written_schedule += '{}, {}\n'.format(event[0], event[1])
f.write(written_schedule)
return written_schedule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment