#!/usr/bin/env python2.7

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
from pprint import pprint
import datetime
from dateutil.parser import parse

def findWednesday(d, weeks):
    days_ahead = 2 - d.weekday()
    if days_ahead < 0:
        days_ahead += weeks * 7
    else:
        days_ahead += (weeks - 1) * 7 #we're on or after wednesday, give less time
    return d + datetime.timedelta(days_ahead)

with open('content/shepherd_assignments.json') as data_file:    
    data = json.load(data_file)

month = raw_input('Enter month, in the format of YYYY-MM: ')

podlingsToReport = data[month].keys()

thisMonth = parse(month + "-01")
podlingReportsDue = findWednesday(thisMonth, 1)
boardMeeting = findWednesday(thisMonth, 3)

dueDateFormat = podlingReportsDue.strftime("%a, %B %d")
boardMeetingFormat = boardMeeting.strftime("%a, %d %B %Y")

print dueDateFormat
print boardMeetingFormat

for podling in podlingsToReport:
    print podling
