def get(self): status = { "temperatures": DB.get_temps(), "taps": DB.get_taps(), } self.write(simplejson.dumps(status))
def run_webserver(): logging.basicConfig(format="%(asctime)-15s %(message)s") parser = argparse.ArgumentParser() parser.add_argument("--init-db", dest="init_db", action="store_true", help="Initialize database and exit.") parser.add_argument("--config-file", dest="config_file", help="Specify location of configuration file.") parser.add_argument("--debug", dest="debug", action="store_true", help="Display debugging information.") parser.add_argument("--logfile", dest="logfile", help="Output to log file instead of STDOUT.") args = parser.parse_args() if args.debug: logging.getLogger().setLevel(logging.DEBUG) if args.logfile: logging.basicConfig(filename=args.logfile) if args.config_file: Config.config_file = args.config_file if args.init_db: DB.init_db() sys.exit(0) webserver = WebServer() webserver.listen()
def post(self): if self.get_argument("update_secret") != Config.get("update_secret"): raise tornado.web.HTTPError(httplib.UNAUTHORIZED) if self.get_argument("tap_id", False) and self.get_argument("pulses", False): DB.update_amount_poured(self.get_argument("tap_id"), self.get_argument("pulses")) if self.get_argument("sensor_id", False) and self.get_argument("deg_c", False): DB.update_temperature(self.get_argument("sensor_id"), self.get_argument("deg_c"))
def post(self, action): user = self.get_secure_cookie("email") if not user and not Config.get("debug_admin"): self.redirect("/auth") return if action == "update": db = DB.connect() tap_id = self.get_argument("tap_id"); beer_id = self.get_argument("beer_id"); cursor = db.cursor() cursor.execute("update taps set beer_id = ?, last_updated = strftime('%s', 'now'), last_updated_by = ?, amount_poured = 0 where tap_id = ?", [beer_id, user, tap_id]) cursor.close() db.commit() self.write(simplejson.dumps({"tap_id": tap_id, "beer_id": beer_id}))
def get(self): self.write(simplejson.dumps(DB.get_taps()))
def get(self): self.write(self.loader.load("index.html").generate(taps=DB.get_taps()))
def get(self): if not self.get_secure_cookie("email") and not Config.get("debug_admin"): self.redirect("/auth") return self.write(self.loader.load("admin.html").generate(taps=DB.get_taps()))