action="store_true", help="Specify to create individual HTML files for each Division") parms.add_argument("--csvfile", dest="csvfile", default="performance.csv", help="Output file for performance CSV") # Do global setup myglobals.setup(parms) conn = myglobals.conn curs = myglobals.curs district = '%02d' % int(parms.district) # Find the latest date in the system and work backwards from there to the beginning of the TM year. today = myglobals.today (latestmonth, latestdate) = latest.getlatest('clubperf', conn) (latestyear, latestmonth) = [int(f) for f in latestmonth.split('-')[0:2]] latestdate = datetime.datetime.strptime(latestdate, "%Y-%m-%d") monthname = [ 'Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ][latestmonth - 1] lateststamp = " from Toastmasters data for the month of " + monthname + latestdate.strftime( ", current through %m/%d/%Y.") # Let's resolve the tmyear if parms.tmyear: if len(parms.tmyear) >= 4: tmyear = int(parms.tmyear[0:4]) elif len(parms.tmyear) == 2: tmyear = 2000 + int(parms.tmyear)
# Define args and parse command line parms = tmparms.tmparms(description=__doc__) parms.add_argument("--tmyear", default=None, action="store", dest="tmyear", help="TM Year for the report. Default is latest year in the database; '2014' means '2014-15'.") parms.add_argument("--newAlignment", dest="newAlignment", default=None, help="CSV file with alignment information to create a report with a new alignment.") parms.add_argument("--outfile", dest="outfile", default="stats.html", help="Output file for the whole District's data") parms.add_argument("--makedivfiles", dest="makedivfiles", action="store_true", help="Specify to create individual HTML files for each Division") parms.parse() conn = dbconn.dbconn(parms.dbhost, parms.dbuser, parms.dbpass, parms.dbname) curs = conn.cursor() district = '%02d' % parms.district # Find the latest date in the system and work backwards from there to the beginning of the TM year. today = datetime.date.today() (latestmonth, latestdate) = latest.getlatest('clubperf', conn) (latestyear, latestmonth) = [int(f) for f in latestmonth.split('-')[0:2]] latestdate = datetime.datetime.strptime(latestdate, "%Y-%m-%d") monthname = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][latestmonth - 1] lateststamp = " from Toastmasters data for the month of " + monthname + latestdate.strftime(", current through %m/%d/%Y.") # Let's resolve the tmyear if parms.tmyear: if len(parms.tmyear) >= 4: tmyear = int(parms.tmyear[0:4]) elif len(parms.tmyear) == 2: tmyear = 2000 + int(parms.tmyear) else: sys.stderr.write('%s is not valid for tmyear.' % parms.tmyear) sys.exit(1) else:
if datetime.today().month > 6: # Fall parms.program = 'stellar' else: # Spring parms.program = 'madness' if not parms.finaldate: parms.finaldate = '3/15' if parms.program == 'madness' else '9/15' if not parms.outfileprefix: parms.outfileprefix = parms.program finaldate = cleandate(parms.finaldate) # We want data for the earlier of "finaldate" or the most recent in the database mostrecent = latest.getlatest('distperf', conn)[1] # Anchor the final date to the proper TM year curs.execute("SELECT MAX(tmyear) FROM lastfor") tmyear = curs.fetchone()[0] if finaldate[5:7] <= '06': finaldate = '%d%s' % (tmyear+1,finaldate[4:]) else: finaldate = '%d%s' % (tmyear,finaldate[4:]) asof = min(finaldate, mostrecent) asofd = datetime.strptime(asof, "%Y-%m-%d") if (asof == finaldate): asofnice = 'final' else: asofnice = 'for ' + asofd.strftime("%B") + " " + asofd.strftime("%d").lstrip('0') # Now, get the clubs which qualify
if not parms.program: if datetime.today().month > 6: # Fall parms.program = 'stellar' else: # Spring parms.program = 'madness' if not parms.finaldate: parms.finaldate = '3/15' if parms.program == 'madness' else '9/15' if not parms.outfileprefix: parms.outfileprefix = parms.program finaldate = cleandate(parms.finaldate) # We want data for the earlier of "finaldate" or the most recent in the database mostrecent = latest.getlatest('distperf', conn)[1] # Anchor the final date to the proper TM year curs.execute("SELECT MAX(tmyear) FROM lastfor") tmyear = curs.fetchone()[0] if finaldate[5:7] <= '06': finaldate = '%d%s' % (tmyear + 1, finaldate[4:]) else: finaldate = '%d%s' % (tmyear, finaldate[4:]) asof = min(finaldate, mostrecent) asofd = datetime.strptime(asof, "%Y-%m-%d") if (asof == finaldate): asofnice = 'final' else: asofnice = 'for ' + asofd.strftime("%B") + " " + asofd.strftime( "%d").lstrip('0')