#!/usr/bin/python # Name: weeklyApprovalCount # Purpose: Count the number of approved requests since a specified date or, if # no date is specified, the number approved in the last 7 days. # Version: 1.10 # Last modified: 2017-04-07 import sys # Check for a date argument on the command line. If one has been entered use # that date as the starting date for locating requests by approval date. Dates # are stored in the database as integers. Enter the date in the form YYYY-MM-DD # where YYY is the year, MM the month, and DD the day. # # If a date has not been provided on the command line, provide a count of requests # approved within the last 7 days. try: sys.argv[1] except IndexError: theDate = "" else: theDate = sys.argv[1] import sqlite3 conn = sqlite3.connect('/Users/jmcamer1/Documents/Work/CRQ/CRQ.db') cursor = conn.cursor() if theDate is not "": sql = "SELECT COUNT(*) FROM Tasks WHERE Approved >= date('" + theDate + "')" print "SQL:", sql else: sql = 'SELECT COUNT(*) FROM Tasks WHERE Approved >= date(CURRENT_DATE,"-7 day")' cursor.execute(sql) result = cursor.fetchone() numApproved = result[0] print numApproved