예제 #1
0
    def get(self):
        status = {
            "temperatures": DB.get_temps(),
            "taps": DB.get_taps(),
            }

        self.write(simplejson.dumps(status))
예제 #2
0
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()
예제 #3
0
    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"))
예제 #4
0
    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}))
예제 #5
0
 def get(self):
     self.write(simplejson.dumps(DB.get_taps()))
예제 #6
0
 def get(self):
     self.write(self.loader.load("index.html").generate(taps=DB.get_taps()))
예제 #7
0
    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()))