#! /usr/bin/env python

"""
Fun with DateTime:
Given a start date, generate appropriate LUG events for the following 7
Tuesdays. start date is of format m/d/yyyy. 

Output Format:

filename: ../OSULUG-Website/content/events/yyyymmdd_wkx.mkd

title: Week x: Topic TBD
datetime: yyyy-mm-dd 18:00:00
category: events
preview: Check back for updates on what we have scheduled for this week!
location: Dearborn 212

---

Meeting placeholder was generated by edunham's lugmeeting.py script :)

When: 6pm

Where: EECS Library, Dearborn 212
"""

import sys
import datetime as dt

def get_dt(mmddyyyy):
    # turn mm/dd/yyyy into a datetime date object
    date = mmddyyyy.split('/')
    month = int(date[0])
    day = int(date[0])
    year = int(date[0])
    return dt.date(year, month, day)

def next_tuesday(date):
    # find first tuesday which follows the given date object
    # day:   S M T W R F S
    # wkd:   0 1 2 3 4 5 6
    # delta: 2 1 0 6 5 4 3
    wkd = date.weekday()
    if wkd <= 2: 
        date = date + dt.timedelta(days = (2 - wkd))
    else:
        date = date + dt.timedelta(days = (9 - wkd)) 
    return date

def make_file(mm, dd, yy, wk):
    mm = str(mm)
    dd = str(dd)
    yy = str(yy)
    wk = str(wk)
    filename = "../OSULUG-Website/content/events/" + yy + '_' + mm + dd + "_wk" + wk + ".mkd"
    f = open(filename, 'w')
    lines = [
        'title: Week ' + wk + ': Topic TBD',
        'datetime: ' + yy + '-' + mm + '-' + dd + ' 18:00:00' ,
        'category: events',
        "preview: check back for updates on this week's schedule!",
        '',
        '---',
        '',
        'Meeting description goes here',
        '',
        'When: 6pm', 
        '',
        'Where: EECS Library'
        ]
    for l in lines:
        f.write(l)
    f.close()

if len(sys.argv) < 2: 
    print "Need a date of the format mm/dd/yyyy"
    exit()

startdate = get_dt(sys.argv[1])
tues = next_tuesday(startdate)
for i in range(0, 9): 
    weeknumber = i + 1
    make_file(tues.month, tues.day, tues.year, weeknumber)
    tues = tues + dt.timedelta(weeks = 1)

#! /usr/bin/env python

"""
Fun with DateTime:
Given a start date, generate appropriate LUG events for the following 7
Tuesdays. start date is of format m/d/yyyy. 

Output Format:

filename: ../OSULUG-Website/content/events/yyyymmdd_wkx.mkd

title: Week x: Topic TBD
datetime: yyyy-mm-dd 18:00:00
category: events
preview: Check back for updates on what we have scheduled for this week!
location: Dearborn 212

---

Meeting placeholder was generated by edunham's lugmeeting.py script :)

When: 6pm

Where: EECS Library, Dearborn 212
"""

import sys
import datetime as dt

def get_dt(mmddyyyy):
    # turn mm/dd/yyyy into a datetime date object
    date = mmddyyyy.split('/')
    month = int(date[0])
    day = int(date[0])
    year = int(date[0])
    return dt.date(year, month, day)

def next_tuesday(date):
    # find first tuesday which follows the given date object
    # day:   S M T W R F S
    # wkd:   0 1 2 3 4 5 6
    # delta: 2 1 0 6 5 4 3
    wkd = date.weekday()
    if wkd <= 2: 
        date = date + dt.timedelta(days = (2 - wkd))
    else:
        date = date + dt.timedelta(days = (9 - wkd)) 
    return date

def make_file(mm, dd, yy, wk):
    mm = str(mm)
    dd = str(dd)
    yy = str(yy)
    wk = str(wk)
    filename = "../OSULUG-Website/content/events/" + yy + '_' + mm + dd + "_wk" + wk + ".mkd"
    f = open(filename, 'w')
    lines = [
        'title: Week ' + wk + ' meeting, topic TBD\n',
        'datetime: ' + yy + '-' + mm + '-' + dd + ' 18:00:00\n' ,
        'category: events\n',
        "preview: check back for updates on this week's schedule!\n",
        '\n---\n\n',
        'Meeting description goes here\n\n',
        'When: 6pm\n\n', 
        'Where: EECS Library\n'
        ]
    for l in lines:
        f.write(l)
    f.close()

def main():
    if len(sys.argv) < 2: 
        print "Need a date of the format mm/dd/yyyy"
        exit()

    startdate = get_dt(sys.argv[1])
    tues = next_tuesday(startdate)
    for i in range(0, 9): 
        weeknumber = i + 1
        make_file(tues.month, tues.day, tues.year, weeknumber)
        tues = tues + dt.timedelta(weeks = 1)

if __name__ == "main":
    main()

make lugmeetings not break when imported