comparison web/index.py @ 337:f575ef538f5d

- Various fixes for web server, kind of works
author Matt Johnston <matt@ucc.asn.au>
date Wed, 13 Jun 2012 23:41:05 +0800
parents ba4c4df13487
children
comparison
equal deleted inserted replaced
336:ba4c4df13487 337:f575ef538f5d
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python2.7
2 2
3 import binascii 3 import binascii
4 import hmac 4 import hmac
5 import zlib 5 import zlib
6 import datetime
7 import time
6 8
7 import bottle 9 import bottle
8 from bottle import route, request 10 from bottle import route, request, response
9 11
10 import config 12 import config
11 import log 13 import log
12 14
13 @route('/update', method='post') 15 @route('/update', method='post')
24 26
25 return "OK" 27 return "OK"
26 28
27 @route('/graph.png') 29 @route('/graph.png')
28 def graph(): 30 def graph():
29 start_secs = int(request.query.start)
30 # url takes time in hours or days 31 # url takes time in hours or days
31 if 'day' in request.query: 32 if 'day' in request.query:
32 start_day = datetime.strptime(request.query.day, '%Y%m%d') 33 start_day = datetime.datetime.strptime(request.query.day, '%Y%m%d')
33 start = time.mktime(start_day.timetuple()) 34 start = time.mktime(start_day.timetuple())
34 length = int(request.query.length) * 3600 * 24 35 length = int(request.query.length) * 3600 * 24
35 else: 36 else:
36 start_hour = datetime.strptime(request.query.hour, '%Y%m%d%H') 37 start_hour = datetime.datetime.strptime(request.query.hour, '%Y%m%d%H')
37 start = time.mktime(start_hour.timetuple()) 38 start = time.mktime(start_hour.timetuple())
38 length = int(request.query.length) * 3600 39 length = int(request.query.length) * 3600
39 40
40 response.set_header('Content-Type', 'image/png') 41 response.set_header('Content-Type', 'image/png')
41 return log.graph_png(start, length) 42 return log.graph_png(start, length)