Created
April 14, 2010 00:41
-
-
Save tstone/365302 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import datetime | |
import json | |
import urllib2 | |
import time | |
LAST_DAY = datetime.datetime(2010, 6, 30) | |
TODAY = datetime.datetime.now() | |
CALENDAR_API_URL = 'http://www.hanalani.org/api/calevents/range.json?cal=all-school-calendar' | |
def get_calendar_data(): | |
start = time.mktime(TODAY.timetuple()) | |
end = time.mktime(LAST_DAY.timetuple()) | |
url = '%s&start=%s&end=%s' % (CALENDAR_API_URL, start, end) | |
response = urllib2.urlopen(url) | |
return response.read() | |
def get_nowork_days(): | |
nowork_days = [] | |
def save_day(day): | |
dt_object = datetime.datetime.strptime(day['start'], '%Y-%m-%d %H:%M:%S') | |
nowork_days.append(dt_object) | |
for day in json.loads(get_calendar_data()): | |
if '(no school)' in day['title'].lower(): | |
save_day(day) | |
elif 'no-school' in day['tags'].lower(): | |
save_day(day) | |
return nowork_days | |
def total_days_left(): | |
return (LAST_DAY - TODAY).days | |
def work_days_left(): | |
nowork_days = get_nowork_days() | |
paid_days_counter = 0; | |
actual_days_counter = 0; | |
for d in range(0, total_days_left()): | |
day = TODAY + datetime.timedelta(days=d) | |
if day.weekday() <= 5 : | |
paid_days_counter += 1 | |
if not datetime.datetime(day.year, day.month, day.day) in nowork_days: | |
actual_days_counter += 1 | |
return (paid_days_counter, actual_days_counter) | |
if __name__ == '__main__': | |
print 'Total Days Left:\t\t%s' % total_days_left() | |
wdl = work_days_left() | |
print 'Total Paid Work Days Left:\t%s' % wdl[0] | |
print 'Total Actual Work Days Left:\t%s' % wdl[1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment