Example #1
0
def create_app(package_name, package_path, debug=False):
    """Returns a :class:`Flask` application instance.

    :param package_name: application package name
    :param package_path: application package path
    :param debug: the debug flag
    """
    app = Flask(package_name, instance_relative_config=True)

    app.config.from_object("mushi.settings")
    app.config.from_envvar("MUSHI_SETTINGS", silent=True)

    if debug:
        app.debug = debug

    app.db_engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"])
    app.teardown_appcontext(remove_db_session)

    register_blueprints(app, package_name, package_path)
    return app
Example #2
0
from datetime import datetime, timedelta
from flask import Flask, g, render_template
from pysumpmon import config, services
from serial import SerialException, SerialTimeoutException
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from threading import Timer
from twilio.exceptions import TwilioException

app = Flask("pysumpmon")
app.db_engine = create_engine(config.DB_CONNECTION_STRING)
app.db_session_factory = sessionmaker(bind=app.db_engine)

distance_sensor = services.DistanceSensorService(config.DISTANCE_SENSOR_PORT)


def log_distance():
    next_log_time = datetime.utcnow() + timedelta(seconds=30)

    try:
        db_session = app.db_session_factory()

        event_suppression = services.EventSuppressionService(db_session)
        notification_log = services.NotificationLogService(db_session)
        sump_water_distance = services.SumpWaterDistanceService(db_session)

        twillio_sms = services.TwilioSMSService(
            config.TWILLIO_ACCOUNT,
            config.TWILLIO_TOKEN,
            config.TWILLIO_NOTIFICATION_FROM,
            config.TWILLIO_NOTIFICATION_TO,