Exemple #1
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(
         basedir, 'test.db')
     self.app = app.test_client()
     db.create_all()
Exemple #2
0
def register():
    if request.method == 'POST':
        db.create_all()
        name = request.form.get('name')
        email = request.form.get('email')
        password = request.form.get('password')

        if not name or not email or not password:
            flash((CSS_ERR, 'Did not register: no name, email or password'))
            return redirect(url_for('.register'))

        try:
            user = schema.User()
            user.name = name
            user.email = email
            user.set_password(password)
            db.session.add(user)
            db.session.commit()
            flash((CSS_SUCC, 'Success!'))
            # log in the user
            login_user(user, remember = True)
        except Exception as e:
            flash((CSS_ERR, str(e)))

        return redirect(url_for('home'))

    return render_template('auth/register.html')
Exemple #3
0
def initdb():
    db.create_all()
    db.session.add(
        User(username='******', email='*****@*****.**', password='******'))
    db.session.add(
        User(username='******', email='*****@*****.**', password='******'))
    db.session.commit()
    print 'Iinitialized the database'
Exemple #4
0
def db(app, request):
    """
    Returns session-wide initialised database.
    """
    _db.init_app(app)
    with app.app_context():
        _db.drop_all()
        _db.create_all()
Exemple #5
0
def db_start():
    engine = create_engine('sqlite:///tmp/likes.db', convert_unicode=True)
    db.create_all()
    db.session.commit()

    like = models.Like()
    like.article ="Dlaczego Kotlin jest przyszłością Androida"
    like.username = "******"
    db.session.add(like)
    db.session.commit()
Exemple #6
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(app.config['BASE_DIR'], 'database', TEST_DB)
        self.app = app.test_client()
        db.create_all()

        # Disable sending emails during unit testing
        self.assertEqual(app.debug, False)
Exemple #7
0
    def setUp(self):
        app.testing = True
        self.app = app.test_client()
        with app.test_request_context():
            db.create_all()
            user = {"tipo": 'admin', "email": "*****@*****.**", "password": '******'}
            headers = {"Content-Type": 'application/json'}

            login = requests.post(
                'https://choutuve-app-server.herokuapp.com/login',
                headers=headers,
                data=json.dumps(user))
            self.token = login.text
Exemple #8
0
def initdb():
    db.create_all()
    db.session.add(
        User(username='******',
             email='*****@*****.**',
             password='******',
             authority=2))
    db.session.add(
        User(username='******',
             email='*****@*****.**',
             password='******',
             authority=2))
    db.session.commit()
    print 'Iinitialized the database'
Exemple #9
0
 def setUp(self):
     application.app_context().push()
     application.config['TESTING'] = True
     application.config['WTF_CSRF_ENABLED'] = True
     application.config['DEBUG'] = False
     # using test database
     application.config['SQLALCHEMY_DATABASE_URI'] = TEST_DB
     self.client = application.test_client()
     db.drop_all()
     db.create_all()
     # create a testing user
     db.session.add(User('*****@*****.**', 'testing', '123456'))
     db.session.commit()
     self.assertEqual(application.debug, False)
def passwords_model_tester():
    print("--------------------------")
    print("Seed Data for Table: Passwords")
    print("--------------------------")
    db.create_all()
    """Tester data for table"""
    t1 = Passwords(name='Admin', password='******')
    table = [t1]
    for row in table:
        try:
            db.session.add(row)
            db.session.commit()
        except IntegrityError:
            print("error")
            db.session.remove()
Exemple #11
0
 def setUp(self):
     db_username = app.config['DB_USERNAME']
     db_password = app.config['DB_PASSWORD']
     db_host = app.config['DB_HOST']
     self.db_uri = "mysql+pymysql://%s:%s@%s/" % (db_username, db_password,
                                                  db_host)
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['BLOG_DATABASE_NAME'] = 'test_blog'
     app.config['SQL_ALCHEMY_DATABASE_URI'] = self.db_uri + app.config[
         'BLOG_DATABASE_NAME']
     engine = sqlalchemy.create_engine(self.db_uri)
     conn = engine.connect()
     conn.execute("commit")
     conn.execute("CREATE DATABASE " + app.config['BLOG_DATABASE_NAME'])
     db.create_all()
     conn.close()
     self.app = app.test_client()
Exemple #12
0
def model_tester():
    print("--------------------------")
    print("Seed Data for Table: users")
    print("--------------------------")
    db.create_all()
    """Tester data for table"""
    u1 = Users(name='Thomas Edison',
               email='*****@*****.**',
               password='******',
               phone="1111111111")
    u2 = Users(name='Nicholas Tesla',
               email='*****@*****.**',
               password='******',
               phone="1111112222")
    u3 = Users(name='Alexander Graham Bell',
               email='*****@*****.**',
               password='******',
               phone="1111113333")
    u4 = Users(name='Eli Whitney',
               email='*****@*****.**',
               password='******',
               phone="1111114444")
    u5 = Users(name='John Mortensen',
               email='*****@*****.**',
               password='******',
               phone="8587754956")
    u6 = Users(name='John Mortensen',
               email='*****@*****.**',
               password='******',
               phone="8587754956")
    # U7 intended to fail as duplicate key
    u7 = Users(name='John Mortensen',
               email='*****@*****.**',
               password='******',
               phone="8586791294")
    table = [u1, u2, u3, u4, u5, u6, u7]
    for row in table:
        try:
            db.session.add(row)
            db.session.commit()
        except IntegrityError:
            db.session.remove()
            print(f"Records exist, duplicate email, or error: {row.email}")
Exemple #13
0
def initdb():
    db.create_all()
    db.session.add(User(username="******", email="*****@*****.**"))
    db.session.add(User(username="******", email="*****@*****.**"))
    """def add_item(title, description):
        db.session.add(Item(title=title, description=description, user=magdaleno))

    for name in ["python","flask","webdev","programming","emacs", "go","golang","javascript","dev","angularjs","django","databases","orm","training"]:
        db.session.add(Tag(name=name))
    db.session.commit()

    add_item("Red Bicycle", "A new red bicycle")
    add_item("Blue Bicycle", "A used blue bicycle")

    anonymous = User(username="******", email="*****@*****.**")
    db.session.add(anonymous)"""
    db.session.commit()

    print('Database Initialized.')
Exemple #14
0
def before_first_request():

    # Create any database tables that don't exist yet.
    db.create_all()

    # Create the Roles "admin" and "end-user" -- unless they already exist
    user_datastore.find_or_create_role(name="admin", description="Administrator")

    # Create two Users for testing purposes -- unless they already exists.
    # In each case, use Flask-Security utility function to encrypt the password.
    encrypted_password = utils.encrypt_password("test")
    if not user_datastore.get_user("*****@*****.**"):
        user_datastore.create_user(email="*****@*****.**", password=encrypted_password)

    # Commit any database changes; the User and Roles must exist before we can add a Role to the User
    db.session.commit()

    # Give one User has the "end-user" role, while the other has the "admin" role. (This will have no effect if the
    # Users already have these Roles.) Again, commit any database changes.
    user_datastore.add_role_to_user("*****@*****.**", "admin")
    db.session.commit()
Exemple #15
0
    def setUp(self):
        application.app_context().push()
        application.config['TESTING'] = True
        application.config['WTF_CSRF_ENABLED'] = True
        application.config['DEBUG'] = False
        # using test database
        application.config['SQLALCHEMY_DATABASE_URI'] = TEST_DB
        self.client = application.test_client()
        db.drop_all()
        db.create_all()
        # create a testing user and testing dogs
        db.session.add(User('*****@*****.**', 'testing', '123456'))
        db.session.add(Dogs(1, "testDog1", "Male", "Adult", "http/pic"))
        db.session.add(Dogs(2, "testDog2", "Male", "Adult", "http/pic"))
        db.session.commit()

        user = User.query.filter_by(email='*****@*****.**').first()
        #login_user(user)

        user_id = user.id
        db.session.add(Favorites(1, 2))
        db.session.add(Favorites(1, 1))
        db.session.commit()
        self.assertEqual(application.debug, False)
Exemple #16
0
def firstRun(materials, materialIDs, feedRates, minTemps, maxTemps, recTemps): 
    # Generate the database tables described in app.py
    db.create_all()

    # Iterate over factory config lists and add+commit to database session
    for i in range(len(materials)):
        db.session.add(Material(name=materials[i]))
        writeValues(FactoryConfig,
            materialIDs[i],
            feedRates[i],
            minTemps[i],
            maxTemps[i],
            recTemps[i]
            )
        writeValues(UserConfig,
            materialIDs[i],
            feedRates[i],
            minTemps[i],
            maxTemps[i],
            recTemps[i]
            )
    print()
    print('Database successfully initialized')
    print()
Exemple #17
0
def recreate_db():
    """Recreates a database."""
    db.drop_all()
    db.create_all()
    db.session.commit()
Exemple #18
0
def db_drop_and_create_all():
    db.session.close()
    db.drop_all()
    db.create_all()
Exemple #19
0
 def setUp(self):
     """Prepare the database tables."""
     db.create_all()
Exemple #20
0
from __init__ import create_app, db
from flask import jsonify, flash, request, make_response
from werkzeug.security import generate_password_hash, check_password_hash
from model import User, DeviceDemo
from flask_login import login_user, logout_user, login_required
from flask_cors import CORS
from test import recognition_with_wav
from unidecode import unidecode
import re

app = create_app()
db.create_all(app=app)
CORS(app)

@app.route('/get-all-devices', methods = ['GET'])
def get():
    response = {}
    result = {}
    tmp = DeviceDemo.query.filter_by(is_active=1).all()
    for i, t in enumerate(tmp):
        if t.status:
            stt = 1
        else:
            stt = 0
        result[str(i)] = t.name + "," + str(stt)
    response[str(len(tmp))] = result
    res = make_response(jsonify(result))
    res.headers['Access-Control-Allow-Origin'] = '*'
    # return ''
    return res
Exemple #21
0
            db.session.commit();
            return render_template("code.html",username = user);
    return render_template("FA.html",form =Auth);

@application.route("/register",methods=['GET','POST'])
def register():
    register = RegisterForm();
    if register.validate_on_submit():
        details = Logindb(register.Username.data, register.Password.data);
        db.session.add(details);
        db.session.commit();
        return render_template("success.html",User = register.Username.data);
    return render_template("Register.html",form = register);

@application.route("/out/<user>",methods=['GET'])
def out(user):
    print user;
    details = Logindb.query.filter_by(username=user).first();
    details.Loginstat ="logged out";
    db.session.add(details);
    db.session.commit();
    return redirect("/");

if __name__ == "__main__":
    db.create_all();
    db.session.commit();
    api.add_resource(delcode,"/delcode/<username>")
    api.add_resource(add_code_api, "/add_code_api/<username>/<string:code>");
    api.add_resource(login_api, '/login_api/<id>/<password>');
    application.run(host='0.0.0.0',debug = True);
Exemple #22
0
def create_db(app):
    # Run db.create_all() at this line to generate the required tables
    db_path = os.path.join(os.path.dirname(__file__), "database/users.db")
    if not os.path.exists(db_path):
        db.create_all(app=app)
def init_db():
    db.create_all()
    '''db.drop_all()
Exemple #24
0
from __init__ import db, create_app
db.create_all(app=create_app())
Exemple #25
0
def initdb():
    db.create_all()
    db.session.add(User(username='******', email='*****@*****.**'))
    db.session.add(Book(title='Wheel of Time', user_id=1))
    db.session.commit()
    print('Initialized the Database')
Exemple #26
0
def create_db():
    """Creates the db tables."""
    db.create_all()
Exemple #27
0
def create_db():
    """Creates database with tables"""
    db.create_all()
Exemple #28
0
def populate():

    db.session.remove()
    db.drop_all()
    db.create_all()
    # db.session.commit()
    # sys.exit()

    # print(len(teams))
    # sys.exit()

    t = 1
    for team_id in teams:
        team = teams[team_id]

        team_entry = Team(
                name = str(team['last_name']),
                conference = team['conference'],
                division =  team['division'],
                site_name = team['site_name'],
                city = team['city'],
                state = team['state'],
                mascot = team['mascot'],
                twitter = team['twitter'],
                citation = team['citation'],
                google_maps = team['google_maps'],
            )
        db.session.add(team_entry)
        db.session.commit()
        print(t)
        t += 1

    # sys.exit()

    # i = 1
    # print(len(players))
    for player_name in players:
        player = players[player_name]
        player_career_stats = player['career_stats_avg_per_game']
        player_season_stats = player['stats_avg_per_game']
        # print(type(player_season_stats))
        print(player_name)
        # sys.exit()
        # print(player['current_team'][player['current_team'].rfind(" ") + 1:])
        # sys.exit()
        player_current_team = player['current_team'][player['current_team'].rfind(" ") + 1:]
        if(player_current_team == 'Blazers'):
            player_current_team = 'Trail Blazers'

        player_entry = Player(
                id = player['id'],
                name = player_name,
                picture = player['picture'],
                experience_years = player['experience_years'],
                draft_info = player['draft_info'],
                position = player['position'],
                player_number = player['player_number'],
                current_team = player['current_team'],
                college = player['college'],
                birth_info = player['birth_info'],
                weight = player['weight'],
                twitter = player['twitter'],
                age = player['age'],
                youtube_link_1 = player['youtube_links'][0],
                youtube_link_2 = player['youtube_links'][1],
                youtube_link_3 = player['youtube_links'][2],
                career_GS = player_career_stats['career_GS'],
                career_REB = player_career_stats['career_REB'],
                career_BLK = player_career_stats['career_BLK'],
                career_FT_PCT = player_career_stats['career_FT%'],
                career_DR = player_career_stats['career_DR'],
                career_MIN = player_career_stats['career_MIN'],
                career_FG_PCT = player_career_stats['career_FG%'],
                career_3PM_A = player_career_stats['career_3PM-A'],
                career_OR = player_career_stats['career_OR'],
                career_FGM_A = player_career_stats['career_FGM-A'],
                career_STL = player_career_stats['career_STL'],
                career_TO = player_career_stats['career_TO'],
                career_3PM_PCT = player_career_stats['career_3P%'],
                career_AST = player_career_stats['career_AST'],
                career_GP = player_career_stats['career_GP'],
                career_PF = player_career_stats['career_PF'],
                career_PTS = player_career_stats['career_PTS'],
                CAREER_FTM_A = player_career_stats['career_FTM-A'],
                season_TO = player_season_stats['TO'],
                season_GS = player_season_stats['GS'],
                season_FG_PCT = player_season_stats['FG%'],
                season__PTS = player_season_stats['PTS'],
                season_OR = player_season_stats['OR'],
                season_GP = player_season_stats['GP'],
                season_PF = player_season_stats['PF'],
                season_REB = player_season_stats['REB'],
                season_FTM_A = player_season_stats['FTM-A'],
                season_BLK = player_season_stats['BLK'],
                season_MIN = player_season_stats['MIN'],
                season_STL = player_season_stats['STL'],
                season_AST = player_season_stats['AST'],
                season_FT_PCT = player_season_stats['FT%'],
                season_FGM_A = player_season_stats['FGM-A'],
                season_3P_PCT = player_season_stats['3P%'],
                season_DR = player_season_stats['DR'],
                season_3PM_A = player_season_stats['3PM-A'],
                citation = player['citation'],
                team_name = player_current_team,
            )
        db.session.add(player_entry)
        db.session.commit()
        # print(i)
        # i += 1

    i = 1
    for game_id in nbaGames:
        game = nbaGames[game_id]
        if game['season'] == '2014':
            home_team_stats = findGameStats(game['game_id'], game['home_id'])
            # print(home_team_stats)
            # sys.exit()
            away_team_stats = findGameStats(game['game_id'], game['away_id'])
            # print(away_team_stats)
            # sys.exit()

            # print("game id: " + game_id + "   home team " + str(game['home_id']) + "  away team: " + str(game['away_id']))
            if not home_team_stats == None:
                game_entry = Game(
                        id = game['id'],
                        home_team = teams[str(game['home_id'])]['last_name'],
                        away_team = teams[str(game['away_id'])]['last_name'],
                        date = game['date'] * 1000,
                        date_string = game['date_string'],
                        home_score = game['home_score'],
                        away_score = game['away_score'],
                        home_box_fgm = home_team_stats['box_fgm'],
                        home_box_fga = home_team_stats['box_fga'],
                        home_box_fg3m = home_team_stats['box_fg3m'],
                        home_box_fg3a = home_team_stats['box_fg3a'],
                        home_box_ftm = home_team_stats['box_ftm'],
                        home_box_fta = home_team_stats['box_fta'],
                        home_box_oreb = home_team_stats['box_oreb'],
                        home_box_dreb = home_team_stats['box_dreb'],
                        home_box_ast = home_team_stats['box_ast'],
                        home_box_stl = home_team_stats['box_stl'],
                        home_box_blk = home_team_stats['box_blk'],
                        home_box_to = home_team_stats['box_to'],
                        home_box_pf = home_team_stats['box_pf'],
                        home_box_pts = home_team_stats['box_pts'],
                        home_box_plus_minus = home_team_stats['box_plus_minus'],
                        away_box_fgm = away_team_stats['box_fgm'],
                        away_box_fga = away_team_stats['box_fga'],
                        away_box_fg3m = away_team_stats['box_fg3m'],
                        away_box_fg3a = away_team_stats['box_fg3a'],
                        away_box_ftm = away_team_stats['box_ftm'],
                        away_box_fta = away_team_stats['box_fta'],
                        away_box_oreb = away_team_stats['box_oreb'],
                        away_box_dreb = away_team_stats['box_dreb'],
                        away_box_ast = away_team_stats['box_ast'],
                        away_box_stl = away_team_stats['box_stl'],
                        away_box_blk = away_team_stats['box_blk'],
                        away_box_to = away_team_stats['box_to'],
                        away_box_pf = away_team_stats['box_pf'],
                        away_box_pts = away_team_stats['box_pts'],
                        away_box_plus_minus = away_team_stats['box_plus_minus'],
                        youtube_link_1 = game['youtube_links'][0],
                        youtube_link_2 = game['youtube_links'][1],
                        youtube_link_3 = game['youtube_links'][2],
                )
                db.session.add(game_entry)
                db.session.commit()
        print(i)
        i += 1
Exemple #29
0
def setup_for_testing():
    db.drop_all()
    db.create_all()
    log('DB created')
    p = Pilot('junu_k', 'junu', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    p.is_admin = True
    p.id_confirmed = True
    p.level = 50
    p.gen = 10
    db.session.add(p)

    gn = GameNight()
    from datetime import datetime
    gn.date = datetime.now()
    db.session.add(gn)

    ps = []
    for i in range(20):
        p = Pilot('junu_k' + str(i), 'junu' + str(i), '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
        p.is_admin = False
        p.id_confirmed = True
        p.level = 12 + i
        p.gen = 2
        ps.append(p)
        db.session.add(p)
        # db.session.commit()
    db.session.commit()

    # team with currently 4 members
    import controllers.team_controller
    tc = controllers.team_controller.TeamController()
    t = add_team('Team1', ps[1])
    add_pilot(t, ps[2], False)
    add_pilot(t, ps[3], False)
    add_pilot(t, ps[4], False)
    add_pilot(t, ps[16], False)
    
    t1id = t.id

    r1 = Roster()
    r1.members = t.members
    r1.team_id = t.id
    r1.game_night_id = gn.id

    db.session.add(r1)
    db.session.commit()

    #team with currently 3 members
    t = add_team('Team2', ps[5])
    add_pilot(t, ps[6], False)
    add_pilot(t, ps[7], False)
    add_pilot(t, ps[14], False)
    add_pilot(t, ps[15], False)

    t2id = t.id

    r1 = Roster()
    r1.members = t.members
    r1.team_id = t.id
    r1.game_night_id = gn.id

    db.session.add(r1)
    db.session.commit()

    #team with currently 5 members
    t = add_team('Team3', ps[8])
    add_pilot(t, ps[9], False)
    add_pilot(t, ps[11], False)
    add_pilot(t, ps[12], False)
    add_pilot(t, ps[13], True)

    t3id = t.id

    r1 = Roster()
    r1.members = t.members
    r1.team_id = t.id
    r1.game_night_id = gn.id

    db.session.add(r1)
    db.session.commit()

    m1 = Match()
    m1.game_night_id = gn.id
    m1.winner_team_id = t1id
    m1.loser_team_id = t2id
    m1.winner_points = 10
    m1.loser_points = 9
    game_type = "capture the flag"

    db.session.add(m1)
    db.session.commit()

    mp1 = MatchParticipant()
    mp1.match_id = m1.id
    mp1.team_id = t1id

    mp2 = MatchParticipant()
    mp2.match_id = m1.id
    mp2.team_id = t2id

    log('DB setup completed')

    


    # p1 = Pilot('junu_k', 'junu', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    # db.session.add(p1)
    # p2 = Pilot('junu_k2', 'junu2', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    # db.session.add(p2)

    # p3 = Pilot('junu_k3', 'junu3', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    # db.session.add(p3)

    # p1.is_admin = True
    # p1.id_confirmed = True
    # p1.level = 12
    # p1.gen = 2

    # p2.id_confirmed = True
    # p2.level = 32
    # p2.gen = 1

    # p3.id_confirmed = True
    # p3.level = 50
    # p3.gen = 10
    # db.session.commit()
    # import controllers.team_controller

    # tc = controllers.team_controller.TeamController()
    # t = add_team('Conquest and Kittens', p1)
    # add_pilot(t, p2, False)
    # add_pilot(t, p3, True)

    db.session.commit()
Exemple #30
0
def db_drop_and_create_all():
    db.drop_all()
    db.create_all()
Exemple #31
0
def create():
    db.create_all()
    return "Great Success", 200
Exemple #32
0
def create_db():
    """Create the database table."""
    db.create_all()
Exemple #33
0
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from __init__ import db
import os.path

db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
    api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
    api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
Exemple #34
0
 def setUp(self):
     app.config["TESTING"] = True
     app.config["CSRF_ENABLED"] = False
     app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(basedir, "test.db")
     self.app = app.test_client()
     db.create_all()
Exemple #35
0
from flask import Blueprint, render_template, flash
from flask_login import login_required, current_user
from __init__ import create_app, db

main = Blueprint('main', __name__)


@main.route('/')  # home page that return 'index'
def index():
    return render_template('index.html')


@main.route('/profile')  # profile page that return 'profile'
@login_required
def profile():
    return render_template('profile.html', name=current_user.name)


app = create_app(
)  # we initialize our flask app using the __init__.py function
if __name__ == '__main__':
    db.create_all(app=create_app())  # create the SQLite database
    app.run(debug=True)  # run the flask app on debug mode
Exemple #36
0
def init_db():
    db.create_all()
Exemple #37
0
from flask import Flask, request, jsonify
from __init__ import app, db, ma
from Models import User, Location
from math import radians, cos, sin, asin, sqrt
from datetime import datetime, timedelta
from google.cloud import tasks
from os import environ, path
from dotenv import load_dotenv
import json

basedir = path.abspath(path.dirname(__file__))
load_dotenv(path.join(basedir, '.env'))

db.create_all()


def distance(latitude1, longitude1, latitude2, longitude2):
    # The math module contains a function named
    # radians which converts from degrees to radians.
    longitude1 = radians(longitude1)
    longitude2 = radians(longitude2)
    latitude1 = radians(latitude1)
    latitude2 = radians(latitude2)

    # Haversine formula
    dlon = longitude2 - longitude1
    dlat = latitude2 - latitude1

    a = sin(dlat / 2)**2 + cos(latitude1) * cos(latitude2) * sin(dlon / 2)**2

    c = 2 * asin(sqrt(a))
Exemple #38
0
def insert_data():
    db.create_all()
    db.session.add(
        User(username="******", email="*****@*****.**", password="******"))
    db.session.commit()
    print('Inserted data')