Ejemplo n.º 1
0
import os
import sys

from flaskext.mysql import MySQL

import forms
from mysql_helper import login_valid, user_exists, update_login_time_to_now, dump_table_to_dict
from shared_lib import get_login_creds

sys.path.append('..')  # Allows us to import stuff in above folder.

from data.mysql_sample_db import UsersDatabase, Config

from flask import render_template, flash, redirect, url_for, Flask

username, password = get_login_creds(os.path.join('..',
                                                  Config.LOGIN_FILE_NAME))

app = Flask(__name__)

mysql = MySQL()

app.config['SECRET_KEY'] = 'itsasecret'

app.config['MYSQL_DATABASE_HOST'] = Config.SERVER_IP
app.config['MYSQL_DATABASE_USER'] = username
app.config['MYSQL_DATABASE_PASSWORD'] = password
app.config['MYSQL_DATABASE_DB'] = Config.DATABASE_NAME

mysql.init_app(app)

connection = mysql.connect()
Ejemplo n.º 2
0
def create_triggers(connection: MySQLdb.connection):
    for trigger in triggers:

        if not has_trigger(connection, trigger.name):

            query = trigger.generate_trigger()

            print(f"Making trigger '{trigger.name}'.")
            print(query)
            connection.query(query)
        else:
            print(f"Trigger '{trigger.name}' already exists.")


if __name__ == '__main__':
    username, password = get_login_creds(
        os.path.join(Config.PROJECT_DIR, Config.LOGIN_FILE_NAME))

    print(f"Using the following credentials from '{Config.LOGIN_FILE_NAME}':")
    print(f'{username}:<PASSWORD>\n')

    connection = MySQLdb.connect(host=Config.SERVER_IP,
                                 user=username,
                                 passwd=password)
    print(connection)
    print(
        "If you see some stuff in angle brackets above, IT WORKED! CONGRATULES!\n"
    )

    # If they don't have the database, create it.
    if not has_database(connection, Config.DATABASE_NAME):
        print(f"DB '{Config.DATABASE_NAME}' does not exist. Creating...")