# HG changeset patch # User Daniel O'Connor # Date 1505133577 -34200 # Node ID db4951d2d303333234587a3f2911752e03c2b495 # Parent 988e511a5f29ba582a800d346017c4eb97550762 Add option to graph N days ago easily. diff -r 988e511a5f29 -r db4951d2d303 agl.py --- 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: