#!/usr/bin/env python2 # coding=utf-8 import cgi import cgitb import datetime import json SECRET = "ahqu2Choshi7sahDme8aePh4iegh8Wee" print "Content-Type: text/html" print "" params = cgi.FieldStorage() if 'secret' in params and params['secret'].value == SECRET: info = dict() info['updated'] = datetime.datetime.now().isoformat() for i in xrange(100): # be prepared for many gateways key = "gw"+str(i).zfill(2) if key in params: try: info[key] = int(params[key].value) except ValueError: # value is not a number pass print "accepted status for "+str(len(info))+" gateways" with open('/home/kasalehlia/ffbs-website/gatewaystatus.json','w') as f: json.dump(info, f) else: print "nothing to see here"