Example #1
0
def getMysqlConnection():
    mysql = MySQL(app)
    app.config['MYSQL_USER'] = '******'
    app.config['MYSQL_PASSWORD'] = '******'
    app.config['MYSQL_DB'] = 'ema'
    app.config['MYSQL_HOST'] = 'localhost'
    mysql.init_app(app)

    connection = mysql.connect
    cursor = connection.cursor()
    return cursor, connection
Example #2
0
def create_app():
    _app = Flask(__name__)

    mysql = MySQL()
    mysql.init_app(_app)

    _app.secret_key = SECRET_KEY
    _app.config['JWT_ACCESS_TOKEN_EXPIRES'] = ACCESS_TIMEOUT
    _app.config['JWT_REFRESH_TOKEN_EXPIRES'] = REFRESH_TIMEOUT

    _app.register_blueprint(bp)

    return _app
Example #3
0
def init_app(app):
    """Register database functions with the Flask app. This is called by
    the application factory.
    """
    # MySQL configurations
    app.config['MYSQL_USER'] = '******'
    app.config['MYSQL_PASSWORD'] = '******'
    app.config['MYSQL_DB'] = 'learningdb'
    app.config['MYSQL_HOST'] = 'localhost'
    print("in init db")
    global mysql
    mysql = MySQL()
    mysql.init_app(app)
Example #4
0
def initialize():
    app = Flask(__name__)
    app.secret_key = 'okboomer'
    app.config['MYSQL_HOST'] = 'localhost'
    app.config['MYSQL_USER'] = '******'
    app.config['MYSQL_PASSWORD'] = '******'
    app.config['MYSQL_DB'] = 'energy'

    mysql = MySQL()
    mysql.init_app(app)

    blacklist = set()
    return app, mysql, blacklist
Example #5
0
def create_api():
    """
    create_api

    Create the flask app with every config needed for the website

    :return: Flask Application
    :rtype: Flask App
    """
    app = Flask(__name__)
    api = Api(app)
    db = MySQL()
    app.config.from_object(Config)
    db.init_app(app)
    initialize_routes(api)
    CORS(app)
    Mail(app)
    return app
Example #6
0
class DataBase:
    db = None
    _app = None

    def __init__(self):
        self.init_db()

    @property
    def connection(self):
        with self._app.app_context():
            return self.db.connect

    def init_db(self):
        self.db = MySQL()
        self._app = Flask(__name__)
        self._app.config['MYSQL_HOST'] = '127.0.0.1'
        self._app.config['MYSQL_PORT'] = 3307
        self._app.config['MYSQL_USER'] = '******'
        self._app.config['MYSQL_PASSWORD'] = '******'
        self._app.config['MYSQL_DB'] = 'nr_db'
        self._app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
        self.db.init_app(self._app)
Example #7
0
import tensorflow
from Talk import ask

app = Flask(__name__)
app.secret_key = os.urandom(24)

# Config MySQL
mysql = MySQL()
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = '******'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'sslchat'
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'

# Initialize the app for use with this MySQL class
mysql.init_app(app)


@app.route('/')
def index():
    cur = mysql.connection.cursor()
    result = cur.execute("SELECT * FROM users WHERE username=%s", ["Om"])

    data = cur.fetchone()
    session['logged_in'] = True
    session['uid'] = 0
    session['s_name'] = 'User'
    uid = session['uid']
    session['name'] = 'Bot'
    session['lid'] = 1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Benevole import Benevole
from flask import Flask
from flask import render_template
from flask import request
from flask_mysqldb import MySQL
from hashlib import md5

app = Flask(__name__)
mysql = MySQL()
app.config['MYSQL_USER'] = '******'
app.config['MYSQL_PASSWORD'] = '******'
app.config['MYSQL_DB'] = 'rfid_lanets'
mysql.init_app(app)
authorize = False
username = None
liste_benevole = []

@app.route('/')
def index():
    return render_template('login.html')

@app.route('/login', methods=['GET','POST'])
def login():
    if request.method == 'POST':
        authorization = authentification(request.form['username'], request.form['password'])
        if authorization:
            global authorize
            authorize = authorization
            global username
Example #9
0
nikoleRoute = NikoleRoute()
accountingRoute = AccountingRoute()
userRoute = UserRoute()

#Flask Configuration
app = Flask(__name__)
CORS(app)

#MySQL Configuration
app.config['MYSQL_HOST'] = constants.MYSQL_HOST
app.config['MYSQL_PORT'] = constants.MYSQL_PORT
app.config['MYSQL_USER'] = constants.MYSQL_USER
app.config['MYSQL_PASSWORD'] = constants.MYSQL_PASS
app.config['MYSQL_DB'] = constants.MYSQL_DB

mySQL.init_app(app)

#Celery Configuration
app.config['CELERY_RESULT_BACKEND'] = constants.REDIS_URL
app.config['CELERY_BROKER_URL'] = constants.REDIS_URL

celery = util.make_celery(app)


## -- CONTAS -- ##
@app.route('/dashboard/api/v1.0/account/insert', methods=['POST'])
def insert_account():
    return Response(accountRoute.insert_account(request),
                    mimetype='application/json')

Example #10
0
# System imports
import re, json
# Package imports
import bleach
from flask import render_template, redirect, request, session
from flask_mysqldb import MySQL
from werkzeug import generate_password_hash, check_password_hash
from app import application

mysql = MySQL()
mysql.init_app(application)


@application.route('/')
@application.route('/index')
def index():
    # If user is logged in, redirect to feed
    if session.get('user'):
        return redirect('/feed')
    # Else present with Login/Register options
    return render_template('index.html')


@application.route('/register', methods=['GET', 'POST'])
def register():
    title = "Tweeter - Register"
    if request.method == "GET":
        return render_template('register.html', title=title)

    elif request.method == "POST":
        try:
Example #11
0
from flask_mysqldb import MySQL
from flask_jwt_extended import (
    JWTManager, jwt_required, create_access_token,
    jwt_refresh_token_required, create_refresh_token,
    get_jwt_identity
)

from flaskblog import app

db = MySQL()
db.init_app(app)
jwt = JWTManager(app)
Example #12
0
from flask import Flask, jsonify, request
from flask_mysqldb import MySQL
from models import *

app = Flask(__name__)
sql = MySQL()

app.config["MYSQL_USER"] = "******"
app.config["MYSQL_PASSWORD"] = "******"
app.config["MYSQL_DB"] = "tatoeba"
app.config["MYSQL_HOST"] = "localhost"
sql.init_app(app)


@app.route("/contributions")
def contributions():
    cursor = sql.connection.cursor()
    cursor.execute("SELECT * FROM contributions ORDER BY datetime DESC")
    result = cursor.fetchall()
    contributions = []

    for row in result:
        contribution = Contribution(row)
        cursor.execute("SELECT * FROM users WHERE id = %d" % row[7])
        contribution.user = User(cursor.fetchall()[0])
        contributions.append(contribution.dict())

    return jsonify(contributions)


@app.route("/sentences")
Example #13
0
 def create_db(self):
     db = MySQL()
     db.init_app(self.app)
     return db
import json
from flask import request
from flask import send_file
from flask import Response
from flask import make_response

dbs = MySQL()

app = Flask(__name__)

app.config['MYSQL_USER'] = '******'
app.config['MYSQL_PASSWORD'] = '******'
app.config['MYSQL_DB'] = 'users'
app.config['MYSQL_HOST'] = '104.155.53.22'

dbs.init_app(app)


@app.route("/")
def test():
    conn = dbs.connection.cursor()
    conn.execute("select * from Users")
    return str(conn.fetchall())


@app.route("/getEvents")
def getEvents():
    conn = dbs.connection.cursor()
    conn.execute("select * from Events where eventDate > CURDATE()")
    headers = [header[0] for header in conn.description]
    resultSet = conn.fetchall()
Example #15
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_mysqldb import MySQL

app5 = Flask(__name__)

app5.config['MYSQL_DATABASE_USER'] = '******'
app5.config['MYSQL_DATABASE_PASSWORD'] = '******'
app5.config['MYSQL_DATABASE_DB'] = 'LibraryDB'
app5.config['MYSQL_DATABASE_HOST'] = 'localhost'
app5.config['MYSQL_DATABASE_PORT'] = 8889

mysql = MySQL()
mysql.init_app(app5)
conn = mysql.connect()
cursor = conn.cursor()


#endpoint for search
@app.route('/search2', methods=['GET', 'POST'])
def search():
    if request.method == "POST":
        book = request.form['name']
        # search by first or last name
        cursor.execute(
            "SELECT first_name, last_name from Users WHERE first_name LIKE %s OR last_name LIKE %s",
            (book, book))
        conn.commit()
        data = cursor.fetchall()
        # all in the search box will return all the tuples
        if len(data) == 0 and book == 'all':
Example #16
0
"""Author: Grant Miller <*****@*****.**>
Purpose: run the following and followers portion of Skitter"""

from pprint import pprint
from flask_mysqldb import MySQL
from flask import Flask
from flask import request
APP = Flask(__name__)

MYSQLDB = MySQL()
APP.config['MYSQL_USER'] = '******'
APP.config['MYSQL_PASSWORD'] = '******'
APP.config['MYSQL_DB'] = 'Skitter'
APP.config['MYSQL_HOST'] = '172.18.0.2'
MYSQLDB.init_app(APP)


@APP.route("/searchUsers", methods=['GET'])
def users():
    """Searches the database for users that match the GET parameter"""
    username = request.args.get('query')
    cur = MYSQLDB.connection.cursor()

    username = username + "%"

    cur.execute("SELECT userid FROM Users WHERE username LIKE %s;",
                (username,))
    data = cur.fetchall()
    pprint(data)

    final = ""
class DBController:
    def __init__(self):
        self.__mysql = MySQL()
        self.__mysql.init_app(app)

    def add_user(self, uname):
        fetch_sql = "SELECT * FROM users WHERE u_name = '{}'".format(uname)
        cursor = self.__mysql.connection.cursor()
        cursor.execute(fetch_sql)
        data = cursor.fetchall()
        if len(data) == 0:
            insert_sql = "INSERT INTO users VALUES (DEFAULT, '{}')".format(
                uname)
            cursor.execute(insert_sql)
            self.__mysql.connection.commit()

    def check_if_user_full(self, threshold):
        fetch_sql = "SELECT count(u_id) FROM users"
        cursor = self.__mysql.connection.cursor()
        cursor.execute(fetch_sql)
        data = cursor.fetchone()

        if data is not None:
            return True if data[0] >= threshold else False

    def get_user_id(self, uname):
        fetch_sql = "SELECT * FROM users WHERE u_name = '{}'".format(uname)
        cursor = self.__mysql.connection.cursor()
        cursor.execute(fetch_sql)
        data = cursor.fetchone()
        return None if data is None else data[0]

    def record_user_click(self, uid, pid, qry, duration):
        click_score = 0
        if duration >= 5 and duration < 15:
            click_score = 1
        else:
            click_score = 2

        insert_sql = "INSERT INTO rel_scores VALUES ({}, '{}', '{}', {}, DEFAULT) ON DUPLICATE KEY UPDATE click_score = {}".format(
            uid, pid, qry, click_score, click_score)
        cursor = self.__mysql.connection.cursor()
        cursor.execute(insert_sql)
        self.__mysql.connection.commit()

    def record_user_rel_sel(self, uid, pid, qry, rel):
        rel_score = 0 if rel == 0 else 2
        insert_sql = "INSERT INTO rel_scores VALUES ({}, '{}', '{}', DEFAULT, {}) ON DUPLICATE KEY UPDATE rel_score = {}".format(
            uid, pid, qry, rel_score, rel_score)
        cursor = self.__mysql.connection.cursor()
        cursor.execute(insert_sql)
        self.__mysql.connection.commit()

    def get_user_rel_scores(self, uid, query, pid=None):
        if pid is None:
            fetch_sql = "SELECT p_id, rel_score + click_score AS score FROM rel_scores WHERE u_id = {} AND qry = '{}'".format(
                uid, query)
            cursor = self.__mysql.connection.cursor()
            cursor.execute(fetch_sql)
            data = cursor.fetchall()
            return None if len(data) == 0 else data
        else:
            fetch_sql = "SELECT rel_score + click_score AS score FROM rel_scores WHERE u_id = {} AND p_id = '{}' AND qry = '{}'".format(
                uid, pid, query)
            cursor = self.__mysql.connection.cursor()
            cursor.execute(fetch_sql)
            data = cursor.fetchone()
            return None if data is None else data[0]