comparison graph.py @ 17:57dece5674e3

Be more clever about what 'today' is
author Daniel O'Connor <darius@dons.net.au>
date Fri, 23 Feb 2018 15:14:15 +1030
parents 29a61ec4755b
children 4d97dfb07169
comparison
equal deleted inserted replaced
16:29a61ec4755b 17:57dece5674e3
64 args = parser.parse_args() 64 args = parser.parse_args()
65 65
66 if args.days is not None and args.days < 0: 66 if args.days is not None and args.days < 0:
67 parser.error('days must be non-negative') 67 parser.error('days must be non-negative')
68 68
69 # If it's before 6am then plot yesterday
70 today = datetime.date.today()
71 if datetime.datetime.now().hour < 6:
72 today -= datetime.timedelta(days = 1)
73
69 selector = [args.start is not None, args.end is not None, args.days is not None] 74 selector = [args.start is not None, args.end is not None, args.days is not None]
70 if selector == [True, True, False]: # Start and end 75 if selector == [True, True, False]: # Start and end
71 pass 76 pass
72 elif selector == [True, False, True] or selector == [True, False, False]: # Start and days or start 77 elif selector == [True, False, True] or selector == [True, False, False]: # Start and days or start
73 if args.days == None: 78 if args.days == None:
76 elif selector == [False, True, True] or selector == [False, True, False]: # End and days or end 81 elif selector == [False, True, True] or selector == [False, True, False]: # End and days or end
77 if args.days == None: 82 if args.days == None:
78 args.days = 1 83 args.days = 1
79 args.start = args.end - datetime.timedelta(days = args.days) 84 args.start = args.end - datetime.timedelta(days = args.days)
80 elif selector == [False, False, True]: # Days 85 elif selector == [False, False, True]: # Days
81 args.end = datetime.date.today() + datetime.timedelta(days = 1) 86 args.end = today + datetime.timedelta(days = 1)
82 args.end = datetime.datetime(args.end.year, args.end.month, args.end.day) 87 args.end = datetime.datetime(args.end.year, args.end.month, args.end.day)
83 args.start = args.end - datetime.timedelta(days = args.days) 88 args.start = args.end - datetime.timedelta(days = args.days)
84 elif selector == [False, False, False]: # Nothing 89 elif selector == [False, False, False]: # Nothing
85 args.start = datetime.date.today() 90 args.start = today
86 args.start = datetime.datetime(args.start.year, args.start.month, args.start.day) 91 args.start = datetime.datetime(args.start.year, args.start.month, args.start.day)
87 args.end = args.start + datetime.timedelta(days = 1) 92 args.end = args.start + datetime.timedelta(days = 1)
88 else: 93 else:
89 parser.error('can\'t specify days, start and end simultaneously') 94 parser.error('can\'t specify days, start and end simultaneously')
90 95