Mercurial > ~darius > hgwebdir.cgi > agl
changeset 14:db4951d2d303
Add option to graph N days ago easily.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 11 Sep 2017 22:09:37 +0930 |
parents | 988e511a5f29 |
children | 7fd3dc0516f8 |
files | agl.py |
diffstat | 1 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/agl.py Mon Sep 11 20:57:54 2017 +0930 +++ b/agl.py Mon Sep 11 22:09:37 2017 +0930 @@ -28,6 +28,7 @@ parser.add_argument('-u', '--update', help = 'Update data', action="store_true") parser.add_argument('-g', '--graph', help = 'Produce graph', action="store_true") parser.add_argument('-f', '--filename', help = 'Filename to save graph as (uses strftime on start)', type = str) + parser.add_argument('-d', '--days', help = 'Days ago to graph', type = int) parser.add_argument('-s', '--start', help = 'Start date for graph (YYYY-MM-DD)', type = valid_date) parser.add_argument('-e', '--end', help = 'End date for graph (YYYY-MM-DD)', type = valid_date) @@ -40,9 +41,6 @@ password = conf.get('DEFAULT', 'password') dbfn = conf.get('DEFAULT', 'db') - if (args.start is None) ^ (args.end is None): - parser.error('Must specify start and end or neither') - if not args.update and not args.graph: parser.error('Nothing to do') @@ -51,10 +49,14 @@ start = datetime.date.today() start = datetime.datetime(start.year, start.month, start.day) + if args.days is not None: + start -= datetime.timedelta(days = args.days) + end = args.end if end is None: end = start + datetime.timedelta(days = 1) end = datetime.datetime(end.year, end.month, end.day) + dbh = sqlite3.connect(dbfn, detect_types = sqlite3.PARSE_DECLTYPES) cur = dbh.cursor() if args.update: