diff web/templog.py @ 362:8fea6144951b

improve graphs
author Matt Johnston <matt@ucc.asn.au>
date Sun, 24 Jun 2012 23:48:11 +0800
parents d6219df77c41
children 62112fc2af21
line wrap: on
line diff
--- a/web/templog.py	Sun Jun 24 14:18:35 2012 +0800
+++ b/web/templog.py	Sun Jun 24 23:48:11 2012 +0800
@@ -32,11 +32,15 @@
     if 'day' in request.query:
         start_day = datetime.datetime.strptime(request.query.day, '%Y%m%d')
         start = time.mktime(start_day.timetuple())
-        length = int(request.query.length) * 3600 * 24
+        length = int(request.query.get('length', 5)) * 3600 * 24
     else:
-        start_hour = datetime.datetime.strptime(request.query.hour, '%Y%m%d%H')
+        if 'hour' in request.query:
+            start_hour = datetime.datetime.strptime(request.query.hour, '%Y%m%d%H')
+        else:
+            start_hour = datetime.datetime.now() - datetime.timedelta(days=1)
+
         start = time.mktime(start_hour.timetuple())
-        length = int(request.query.length) * 3600
+        length = int(request.query.get('length', 36)) * 3600
 
     response.set_header('Content-Type', 'image/png')
     return log.graph_png(start, length)