Exemplo n.º 1
0
def create_app(logPath):
    sys.path.insert(0, "/Users/ashwaheg/Desktop/4trump/")
    app = Flask(__name__)
    CORS(app)
    config_file_name = "app_info.conf"
    app_config = ConfigParser()
    if os.path.isfile(config_file_name):
        app_config.read(config_file_name)
    else:
        raise FileNotFoundError

    for section in app_config.sections():
        for options in app_config.options(section):
            app.config[options] = app_config.get(section, options)
    app.config["SECRET_KEY"] = app.config["secret_key"]

    #create db
    if not os.path.isfile(app.config["sqlitedb"]):
        with app.app_context():
            from utils.db import init_db
            init_db()
    with app.app_context():
        from bluep.db import db_blueprint
        app.register_blueprint(db_blueprint, url_prefix='/db')
    from bluep.state import state_blueprint
    app.register_blueprint(state_blueprint, url_prefix='/state')
    from bluep.webpages import ui_blueprint
    app.register_blueprint(ui_blueprint, url_prefix='/')

    gunicorn_error_logger = logging.getLogger('gunicorn.error')
    rotationHandler = logging.handlers.TimedRotatingFileHandler(logPath,
                                                                when="H",
                                                                interval=1,
                                                                backupCount=30)
    logFormatter = logging.Formatter(
        fmt='[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
        #fmt='%(asctime)s.%(msecs)03d %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    rotationHandler.setFormatter(logFormatter)
    gunicorn_error_logger.addHandler(rotationHandler)
    app.logger.setLevel(logging.INFO)
    gunicorn_error_logger.info("App is being started.")
    #login part
    login = LoginManager(app)
    login.login_view = 'state_blueprint.login'

    from utils.db import check_user
    from utils.user import User

    @login.user_loader
    def load_user(id):
        if check_user(id):
            return User(id=id)
        else:
            return None

    return app
Exemplo n.º 2
0
def init_app():
    """
    Initialize application and depend module for it.

    Returns:
        app: instance of application
    """
    app = web.Application()

    loop = asyncio.get_event_loop()
    db = loop.run_until_complete(init_db())
    app['db'] = db

    client_uri = os.getenv('CLIENT_URI', '*')
    cors = aiohttp_cors.setup(app,
                              defaults={
                                  client_uri:
                                  aiohttp_cors.ResourceOptions(
                                      expose_headers='*',
                                      allow_headers='*',
                                      allow_credentials=True,
                                      allow_methods=['POST', 'GET', 'OPTIONS'],
                                  ),
                              })

    init_routes(app, cors)

    return app
Exemplo n.º 3
0
    def __init__(self, client):
        self.client = client
        # Initiate an instance of levels to use its updateXp function
        self.levels = levels(client)

        self.cnx = init_db()
        self.cursor = self.cnx.cursor(buffered=True)
Exemplo n.º 4
0
    def __init__(self, client):
        self.client = client
        self.cnx = init_db()
        self.cursor = self.cnx.cursor(buffered=True)

        # Initialize the eastereggs after reload/load
        self.initEggs(self.cursor, self.cnx)
Exemplo n.º 5
0
    def __init__(self, client):
        self.client = client

        self.cnx = init_db()
        self.cursor = self.cnx.cursor(buffered=True)
Exemplo n.º 6
0
def initdb_cli_command():
    DBUtils.init_db(app.config)
Exemplo n.º 7
0
 def __init__(self, client):
     self.client = client
     self.cnx = init_db()
     self.cursor = self.cnx.cursor(buffered=True)
     self.active_authors = []
Exemplo n.º 8
0
    generate_procedures_report,
    generate_encounters_report,
)
from transformers.patient import PatientTransformer
from transformers.encounter import EncounterTransformer
from transformers.observation import ObservationTransformer
from transformers.procedure import ProcedureTransformer
from models import Patient, Encounter


if __name__ == "__main__":
    session = get_session()
    engine = session.get_bind()
    # create tables if they don't exist
    print("Creating Tables..")
    init_db()

    # First clear all records
    print("Removing Existing Data..")
    drop_all_data(session)

    # Import Patients
    print("Importing Data..")
    deserialize_and_save(session, "patients", PatientTransformer)
    Patient.create_source_id_index(session)

    deserialize_and_save(session, "encounters", EncounterTransformer)
    Encounter.create_source_id_index(session)

    deserialize_and_save(session, "procedures", ProcedureTransformer)
Exemplo n.º 9
0
def make_db_table(sql):
    '''创建数据库表'''
    conn = db.init_db()
    cursor = conn.cursor()
    cursor.execute(sql)
    cursor.close()
Exemplo n.º 10
0
from utils.db import Producer, Consumer, init_db, db_session

init_db()

p = Producer('Fridge Door', 'Fires when someone opens the fridge door can\'t have them stealing snacks yo', 'fridge_door')

c = Consumer('Kitchen Alarm', 'Ear splitting alarm in the kitchen')
c1 = Consumer('Text Message', 'Send me a text message')

p.consumers = [c, c1]

db_session.add(p)
db_session.add(c)
db_session.add(c1)
db_session.commit()
Exemplo n.º 11
0
from flask import Flask, render_template, request, session, redirect, url_for, flash
import os
from utils import db

app = Flask(__name__)
app.secret_key = "235jk-6fa_qwef79034jk"
db.init_db()


@app.route("/")
def index():
    if "username" in session:
        return redirect(url_for("profile"))
    return render_template("index.html", log=False)


@app.route("/signup")
def signup():
    if "username" in session:
        return redirect(url_for("profile"))
    return render_template("signup.html", log=False)


@app.route("/login")
def login():
    if "username" in session:
        return redirect(url_for("profile"))
    return render_template("login.html", log=False)


@app.route("/directions")