#!/usr/bin/env python # BirthDay.py # Copyright (c) 2008 Moo. All rights reserved. #################################################################################################### print "Content-Type: text/html\n\n", print "Date Calculator" print """
Enter a date by clicking the date select link! You can manually enter the year if you wish
Select A Date

Click here to find how many days you've been alive
Click here to find what day of the week a certain day falls on
""" #################################################################################################### version="0.4_CGI" from datetime import date from calendar import * import time import cgi import sys form = cgi.FieldStorage() class Birthday: def __init__(self,*args): pass def daysOld(self,month,day,year): self.month=month self.day=day self.year=year TheBirthday= date(year,month,day) now=date.today() totaldays = now - TheBirthday return totaldays def results(self): print "If you were born on %s/%s/%s then you are %s days old." % (d.month , d.day , d.year ,d.days.days) class weekDay: def weekDay(self,month,day,year): self.month=month self.day=day self.year=year theCalnum= weekday(year,month,day) theWeekDay=day_name[theCalnum] return theWeekDay def results(self): print "%s/%s/%s falls on a %s." % (w.month , w.day , w.year ,w.weekDay) class untilDay: def until(self,month1,day1,year1,month2,day2,year2): self.month1=month1 self.day1=day1 self.year1=year1 self.month2=month2 self.day2=day2 self.year2=year2 date1=date(year1,month1,day1) date2=date(year2,month2,day2) if date1 > date2: daysUntil = date1 - date2 if date1 < date2: daysUntil= date2 - date1 if date1 == date2: print "Those two dates are equal!" sys.exit() return daysUntil def results(self): print "If date one was %s/%s/%s then date two is %s days away." % (u.month1 , u.day1 , u.year1 ,u.days.days) if (form.has_key("submit")): status = '' if form.getvalue("mode") == "d" or form.getvalue("mode") == "none": d= Birthday() d.days=d.daysOld(int(form.getvalue("month1")),int(form.getvalue("day1")),int(form.getvalue("year1"))) d.results() status = 'Completed' if form.getvalue("mode") == "w": w= weekDay() w.weekDay=w.weekDay(int(form.getvalue("month1")),int(form.getvalue("day1")),int(form.getvalue("year1"))) w.results() status = 'Completed' if form.getvalue("mode") == "y": y= yearDay() y.yearDay=y.yearDay(int(sys.argv[2]),int(sys.argv[3]),int(sys.argv[4])) y.results() status = 'Completed' if form.getvalue("mode") == "u": u=untilDay() u.days=u.until(int(form.getvalue("month1")),int(form.getvalue("day1")),int(form.getvalue("year1")),int(form["month2"]),int(form["day2"]),int(form["year2"])) u.results() status = 'Completed' print ""