Specify end date on command line

This commit is contained in:
Sandy Walsh 2013-02-11 19:53:20 -06:00 committed by root
parent eb834bcc9d
commit 56f65969e1

View File

@ -1,6 +1,7 @@
import datetime
import json
import sys
import time
import prettytable
@ -14,14 +15,24 @@ from stacktach import models
if __name__ != '__main__':
sys.exit(1)
yesterday = datetime.datetime.utcnow().date() - datetime.timedelta(days=1)
if len(sys.argv) == 2:
try:
t = time.strptime(sys.argv[1], "%Y-%m-%d")
yesterday = datetime.datetime(*t[:6])
except Exception, e:
print e
print "Usage: python requests.py YYYY-MM-DD (the end date)"
sys.exit(1)
hours = 0
length = 24
now = datetime.datetime.utcnow()
start = now - datetime.timedelta(hours=hours+length)
end = now - datetime.timedelta(hours=hours)
start = datetime.datetime(year=yesterday.year, month=yesterday.month, day=yesterday.day)
end = start + datetime.timedelta(hours=length-1, minutes=59, seconds=59)
print "Generating report for %s to %s" % (start, end)
dnow = dt.dt_to_decimal(now)
dstart = dt.dt_to_decimal(start)
dend = dt.dt_to_decimal(end)