Ejemplo n.º 1
0
def create_app(config=None):
    new_app = Flask(__name__,
                    template_folder='../react_app/build',
                    static_folder='../react_app/build/static')
    new_app.config.from_object(config)

    with new_app.app_context():
        jwt.init_app(new_app)
        bcrypt.init_app(new_app)
        cors.init_app(new_app)
        mysql.init_app(new_app)
        mail.init_app(new_app)

    from model import temp_blacklist

    @jwt.token_in_blacklist_loader
    def check_if_token_in_blacklist(decrypted_token):
        return decrypted_token['jti'] in temp_blacklist

    # Let react handle routing
    @new_app.route('/', defaults={'path': ''})
    @new_app.route('/<path:path>')
    def serve(path):
        if path and os.path.exists(safe_join(new_app.template_folder, path)):
            return send_from_directory(new_app.template_folder, path)
        else:
            return send_from_directory(new_app.template_folder, 'index.html')

    from resources.authentication import (UserRegistration, UserLogin,
                                          TokenRefresh, UnsetToken, AdminLogin,
                                          AdminRegister)
    from resources.user import GetUserInfo, UpdateUserInfo
    from resources.products import (TrackProduct, NewComments, GetComments,
                                    GetSpecificProduct)
    from resources.admin import Announcement

    api.add_resource(UserRegistration, '/register')
    api.add_resource(UserLogin, '/login')
    api.add_resource(TokenRefresh, '/refresh')
    api.add_resource(UnsetToken, '/revoke')
    api.add_resource(GetUserInfo, '/user')
    api.add_resource(UpdateUserInfo, '/user/<string:option>')
    api.add_resource(TrackProduct, '/product')
    api.add_resource(GetSpecificProduct,
                     '/product/<string:retailer>/<string:pid>')
    api.add_resource(NewComments, '/comment')
    api.add_resource(GetComments,
                     '/comment/<string:retailer>/<string:prod_id>')
    api.add_resource(AdminLogin, '/admin-login')
    api.add_resource(AdminRegister, '/admin-register')
    api.add_resource(Announcement, '/announcement')

    api_bp = Blueprint('api', __name__)
    api.init_app(api_bp)
    new_app.register_blueprint(api_bp, url_prefix='/api')
    return new_app
Ejemplo n.º 2
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config['production'])

    from scraper.student_api import api_bp
    from scraper.scrape import scraper
    from student.student import student
    from student.college import college

    app.register_blueprint(api_bp)
    app.register_blueprint(scraper)
    app.register_blueprint(student)
    app.register_blueprint(college)

    mysql.init_app(app)

    return app
from flask import Flask, request, jsonify, send_from_directory, send_file, Blueprint, current_app
from flaskext.mysql import MySQL
import csv
import hashlib
from time import gmtime, strftime
from extensions import mysql
from tools import *

app = Flask(__name__, static_folder='static')

app.config['MYSQL_DATABASE_USER'] = '******'
app.config['MYSQL_DATABASE_PASSWORD'] = '******'
app.config['MYSQL_DATABASE_DB'] = 'mmcorps'
app.config['MYSQL_DATABASE_HOST'] = '10.162.80.9'

mysql.init_app(app)


def updateValues():
    conn = mysql.connect()
    cursor = conn.cursor()

    print("done")
    cursor.execute("SELECT * FROM heart_rate_logs;")
    data = cursor.fetchall()
    for item in data:
        timestamp = float(item[2]) + 2592000.0
        cursor.execute("UPDATE heart_rate_logs SET timestamp=%d WHERE id=%i;" %
                       (timestamp, int(item[0])))

    print("done")
Ejemplo n.º 4
0
from flask import Flask, render_template

from extensions import mysql
import controllers

# Initialize Flask app with the template folder address
app = Flask(__name__, template_folder='templates')

# Initialize MySQL database connector
app.config['MYSQL_USER'] = '******'
app.config['MYSQL_PASSWORD'] = '******'
app.config['MYSQL_DB'] = 'discussion1'
mysql.init_app(app)

# Register the controllers
app.register_blueprint(controllers.album)
app.register_blueprint(controllers.albums)
app.register_blueprint(controllers.pic)
app.register_blueprint(controllers.main)

# Listen on external IPs
# For us, listen to port 3000 so you can just run 'python app.py' to start the server
if __name__ == '__main__':
    # listen on external IPs
    app.run(host='0.0.0.0', port=3000, debug=True)
Ejemplo n.º 5
0
from flask import Flask, render_template, redirect, url_for, send_from_directory
from route import private, page, public
from extensions import mysql, mongoDB, query, html_escape, getConfig

cfg = getConfig()

app = Flask(__name__)
app.config.from_object(cfg)

mysql.init_app(app.config)
mongoDB.init_app(app.config)
query.init_db(mysql.get_connection(), mongoDB.get_client())

app.register_blueprint(page.app)
app.register_blueprint(private.app, url_prefix="/api/private")
app.register_blueprint(public.app, url_prefix="/api/public")

@app.route("/")
def index():
	return redirect(url_for('Page.graph_view'))

@app.route("/favicon.ico")
def favicon():
	return send_from_directory("static","img/bulb.ico")

@app.errorhandler(404)
def page_not_found(e):
	return render_template('404.html'), 404

@app.errorhandler(403)
def page_forbidden(e):