Beispiel #1
0
def create_app():
    app = Flask(__name__)
    app.config.from_object('server.config.Config')
    app.config['JSON_AS_ASCII'] = False
    init_db(app)
    register_command(app)
    app.register_blueprint(api)
    return app
Beispiel #2
0
def create_user():
    init_db()
    # u = db.query(User).first()
    # logger.debug('User exists? %r' % u)
    # if not u:
    #     from flask_security.utils import hash_password
    #
    #     user_datastore.create_user(username='******',
    #                                email=os.environ.get('DEFAULT_EMAIL'),
    #                                password=hash_password(os.environ.get('DEFAULT_PASSWORD')),
    #                                seconds_available=600)
    db.commit()
def create_app(config=None):
    app = Flask(__name__)
    if config:
        app.config.from_object(config)
    else:
        app.config.from_object(Config)

    if app.config.get("SQLALCHEMY_DATABASE_URI"):
        db.init_app(app)
        db.app = app
        init_db(db)

    return app
Beispiel #4
0
def create_app():
    # Create the flask instance and configure the app's secret key and database
    app = Flask(__name__)
    app.config.from_mapping(SECRET_KEY="dev", )

    # Load the instance config, if it exists
    app.config.from_pyfile("config.py", silent=True)

    init_db()

    # app.teardown_appcontext() tells Flask to call that function when cleaning
    # up after returning the response.
    app.teardown_appcontext(close_db)

    # Registering blueprints
    app.register_blueprint(auth_bp)
    app.register_blueprint(portfolio_bp)
    app.register_blueprint(index_bp)
    app.register_blueprint(follow_bp)
    app.register_blueprint(transaction_bp)
    app.register_blueprint(feed_bp)

    return app
Beispiel #5
0
 def start_requests(self):
     init_db(config)
     urls = ["https://g1.globo.com/ciencia-e-saude/"]
     for url in urls:
         yield scrapy.Request(url=url, callback=self.parse)
Beispiel #6
0
def create_data():
    env = sys.argv[1] if len(sys.argv) > 1 else 'default'
    print(env)

    app = Flask(__name__)

    app.config.from_pyfile('server/config/api/default.py')
    app.config.from_pyfile('server/config/api/%s.py' % env, silent=True)

    init_db(app.config['DATABASE_URI'])

    lights = Schedule(open_time_sec=5 * 60 * 60, run_for_sec=16 * 60 * 60)
    db_session.add(lights)

    fans = Schedule(open_time_sec=5 * 60 * 60,
                    run_for_sec=5 * 60,
                    repeat_every=60 * 60)
    db_session.add(fans)

    db_session.flush()

    p = Pin(pin_id=37, name='L1.1')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=35, name='L1.2')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=33, name='L1.3')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=31, name='L1.4')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=13, name='L1.5')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=16, name='L2.1')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=26, name='L2.2')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=29, name='L2.3')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=18, name='L2.4')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=12, name='L2.5')
    p.schedule_id = lights.id
    db_session.add(p)

    p = Pin(pin_id=36, name='Ventilation')
    p.schedule_id = fans.id
    db_session.add(p)
    db_session.flush()
Beispiel #7
0
    for dog_json in dog_jsons:
        print("{id}: {name}".format(**dog_json))

    parks = fetch_parks_in_zip(zipcode)
    db_session.add_all(parks)
    db_session.commit()

    for park in parks:
        print(park)


if __name__ == "__main__":
    from server.database import db_session, init_db
    from server.geo import zips
    start_zip = 75001
    end_zip = 75009
    try:
        init_db()
        shelter_ids = UniqueQueue()
        for zipcode in zips[zips.index(start_zip):zips.index(end_zip) + 1]:
            print(zipcode)
            scrape_and_commit_zip(zipcode, shelter_ids)
            print()
    except Exception as e:
        db_session.remove()
        raise e
    db_session.remove()
    # pprint(fetch_shelter_details("Henderson County Humane", "32.1991,-95.8661"))
    # fetch_park_info("TX", 2, 0)
Beispiel #8
0
def flask_init_db():
    init_db()
Beispiel #9
0
Datei: main.py Projekt: jdupl/iot
    env = sys.argv[1] if len(sys.argv) > 1 else 'default'
    platform = sys.argv[2] if len(sys.argv) > 2 else 'computer'

    atexit.register(interrupt)
    # Get the GPIO wrapper for the platform
    GPIO = platform_resolver[platform]

    app = Flask(__name__)

    app.config.from_pyfile('server/config/api/default.py')
    app.config.from_pyfile('server/config/api/%s.py' % env, silent=True)

    app.config['GPIO'] = GPIO()

    init_db(app.config['DATABASE_URI'])

    from server.views import relays_blueprint, static_blueprint

    app.register_blueprint(relays_blueprint)
    app.register_blueprint(static_blueprint)

    # Setup Flask process
    relay_api_process = Process(target=launch_api, args=(app,))
    child_processes.append(relay_api_process)
    relay_api_process.start()
    sleep(0.5)

    # Setup scheduler process
    relays_updater_process = Process(target=start_scheduler)
    child_processes.append(relays_updater_process)
Beispiel #10
0
from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager

from server.database import init_db
from server.endpoints import register_endpoints
from server.managers.project_manager import ProjectManager
from server.managers.user_manager import UserManager
from server.managers.notification_manager import NotificationManager

# create and configure the app
app = Flask(__name__)
CORS(app, supports_credentials=True)
jwt = JWTManager(app)
db = init_db()

notification_manager = NotificationManager(db)
user_manager = UserManager(app, db, jwt, notification_manager)
project_manager = ProjectManager(app, db, notification_manager)

api = register_endpoints(app, db, user_manager, project_manager, notification_manager)

app.config.from_mapping(
    SECRET_KEY=b"\xb6\x07\x03a[(\xaaj\x13'\xc8X\xd5%}\x9f",
    JWT_SECRET_KEY=b"\xf8u4\x0f\xfc\xa2\x06\xc5v\xf3\xa1\xfal{\x95\xb8",
    JWT_BLACKLIST_ENABLED=True,
    JWT_BLACKLIST_TOKEN_CHECKS=["access", "refresh"],
    # Access tokens to expire in 1 day
    JWT_ACCESS_TOKEN_EXPIRES=timedelta(1, 0, 0),
)
Beispiel #11
0
def init_app():
    clear_db()
    init_db()
    create_users()
    #create_games()
    run_server()
Beispiel #12
0
    env = sys.argv[1] if len(sys.argv) > 1 else 'default'
    platform = sys.argv[2] if len(sys.argv) > 2 else 'computer'

    atexit.register(interrupt)
    # Get the GPIO wrapper for the platform
    GPIO = platform_resolver[platform]

    app = Flask(__name__)

    app.config.from_pyfile('server/config/api/default.py')
    app.config.from_pyfile('server/config/api/%s.py' % env, silent=True)

    app.config['GPIO'] = GPIO()

    init_db(app.config['DATABASE_URI'])

    from server.views import relays_blueprint, static_blueprint

    app.register_blueprint(relays_blueprint)
    app.register_blueprint(static_blueprint)

    # Setup Flask process
    relay_api_process = Process(target=launch_api, args=(app, ))
    child_processes.append(relay_api_process)
    relay_api_process.start()
    sleep(0.5)

    # Setup scheduler process
    relays_updater_process = Process(target=start_scheduler)
    child_processes.append(relays_updater_process)