#!/usr/bin/env python3 import argparse from potnanny.application import create_app, configure_database from potnanny.config import DebugConfig if __name__ == '__main__': parser = argparse.ArgumentParser(description='Run Flask App') parser.add_argument('--debug', action='store_true', help='run werkzeug server in debug config mode') args = parser.parse_args() if args.debug: app = create_app(config=DebugConfig) else: app = create_app() configure_database(app) app.run()
def sensor_id(addr, name): s = Sensor.query.filter(Sensor.address == addr).first() if s: return s.id obj = Sensor(name, addr) db.session.add(obj) db.session.commit() return obj.id if __name__ == '__main__': app = create_app() app.app_context().push() poll = Setting.query.get(1) if not poll: # logger.error("could not determine polling interval from db") sys.stderr.write( "error. could not determine polling interval from db\n") sys.exit(1) if now.minute % poll.interval > 0: # not the right time to be running this. exit sys.exit(0) main()
def create_app(self): self.app = create_app(config=TestConfig) return self.app