diff web/index.py @ 30:13fcf497f8b7

parse the arguments for start/length
author Matt Johnston <matt@ucc.asn.au>
date Tue, 12 Jun 2012 23:43:49 +0800
parents 048143905092
children 5e75e08d20ac
line wrap: on
line diff
--- a/web/index.py	Tue Jun 12 23:27:53 2012 +0800
+++ b/web/index.py	Tue Jun 12 23:43:49 2012 +0800
@@ -26,7 +26,19 @@
 
 @route('/graph.png')
 def graph():
-    pass
+    start_secs = int(request.query.start)
+    # url takes time in hours or days
+    if 'day' in request.query:
+        start_day = datetime.strptime(request.query.day, '%Y%m%d')
+        start = time.mktime(start_day.timetuple())
+        length = int(request.query.length) * 3600 * 24
+    else:
+        start_hour = datetime.strptime(request.query.hour, '%Y%m%d%H')
+        start = time.mktime(start_hour.timetuple())
+        length = int(request.query.length) * 3600
+
+    response.set_header('Content-Type', 'image/png')
+    return log.graph_png(start, length)
 
 @route('/')
 def top():