def __init__(self, app): # MySQL configurations app.config['MYSQL_HOST'] = dbConst['host'] app.config['MYSQL_USER'] = dbConst['user'] app.config['MYSQL_DB'] = dbConst['db'] app.config['MYSQL_USE_UNICODE'] = dbConst['use_unicode'] app.config['MYSQL_CHARSET'] = dbConst['charset'] self.mysql = MySQL(app) # path to saved recordings self.recordings_path = app.config['MAIN_RECORDINGS_PATH'] # needed to sanitize the dynamic sql creation in insertGeneralData # keep a list of allowed column names for insertions etc. depending on the table (device, isntructor, etc) self.allowedColumnNames = { 'device': ['userAgent', 'imei'], 'instructor': ['name', 'email', 'phone', 'address'], 'speaker': ['name', 'deviceImei'], 'speaker_info': ['speakerId', 's_key', 's_value'] } # generate list of currently valid tokens according to 'valid' column in table token. #self.invalid_token_ids = self.getInvalidTokenIds() # messes up WSGI script for some f*****g reason self.invalid_token_ids = None
def connect_to_db(init_type): # connect to database if init_type == "openshift" : app.config['MYSQL_USER'] = os.environ['OPENSHIFT_MYSQL_DB_USERNAME'] app.config['MYSQL_PASSWORD'] = os.environ['OPENSHIFT_MYSQL_DB_PASSWORD'] app.config['MYSQL_DB'] = 'dkdbprojects' app.config['MYSQL_HOST'] = os.environ['OPENSHIFT_MYSQL_DB_HOST'] else : app.config['MYSQL_USER'] = '******' app.config['MYSQL_PASSWORD'] = '******' app.config['MYSQL_DB'] = 'dkdbprojects' app.config['MYSQL_HOST'] = 'localhost' global mysql mysql = MySQL() mysql.init_app(app) return
def __init__(self, config_dict): """ Initializes a singleton DB object :param config_dict: a dictionary contaning all config variables to be passed to the flask.ext.mysqldb extension :return: None """ if DB.instance is None: DB.instance = MySQL(config_dict)
def createApp(config="voting.config"): #initialize app app = Flask("voting") with app.app_context(): app.config.from_object(config) #setup db db = MySQL(app) #import stuff from this app so we can add blue prints from voting.views import views from voting.auth import auth from voting.utils import utils #register blue print so pages will render app.register_blueprint(views) app.register_blueprint(auth) app.register_blueprint(utils) return app
from flask import Flask, render_template from flask.ext.mysqldb import MySQL from flask.ext.login import LoginManager from flask.ext.mail import Mail mysql = MySQL() login_manager = LoginManager() login_manager.login_view = "user.user_login_route" mail = Mail()
from flask.ext.mysqldb import MySQL from flask_ask import Ask, statement, question import logging from random import randint import random, threading, webbrowser app = Flask(__name__) query="" port=5000 app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = '******' app.config['MYSQL_PASSWORD'] = '' app.config['MYSQL_DB'] = 'test' mysql = MySQL(app) ask = Ask(app, "/") logging.getLogger("flask_ask").setLevel(logging.DEBUG) @ask.intent("DisplayMeIsIntent") def display_me(displayme): global query query="" words = displayme.split(' ') for word in words: if word=='select': query=query+word+" * " else: query=query+" "+word try:
from flask import Flask, render_template, json, request,redirect,session,jsonify, url_for from flask.ext.mysqldb import MySQL from werkzeug import generate_password_hash, check_password_hash from werkzeug.wsgi import LimitedStream import uuid import os mysql = MySQL() # print mysql app = Flask(__name__) app.secret_key = 'why would I tell you my secret key?' # MySQL configurations app.config['MYSQL_DATABASE_USER'] = '******' app.config['MYSQL_DATABASE_PASSWORD'] ='******' app.config['MYSQL_DATABASE_DB'] = 'emailSpam' app.config['MYSQL_DATABASE_HOST'] = 'localhost' mysql.init_app(app) # Default setting pageLimit = 5 class StreamConsumingMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): stream = LimitedStream(environ['wsgi.input'], int(environ['CONTENT_LENGTH'] or 0)) environ['wsgi.input'] = stream
# PixelGram Backend # ##################### # application.py # ##################### # Includes import os, uuid, re from flask import Flask, render_template, json, redirect, session, request from flask.ext.mysqldb import MySQL from werkzeug import generate_password_hash, check_password_hash, secure_filename import resizr application = Flask(__name__) mysql = MySQL() # 504 bit session key application.secret_key = '?KzNp>j0-7ec;4c9zG]@tjrBy3uCZNeEsDFm*!%buG7A97?#3ANL*97;D?(jpe9' # Config MySQL # Don't run as root in production! application.config['MYSQL_USER'] = '******' application.config['MYSQL_PASSWORD'] = '******' application.config['MYSQL_DB'] = 'PixelGram' application.config['MYSQL_HOST'] = 'localhost' mysql.init_app(application) # Define uploads folder and allowed file types - Should not be changed for now! application.config['UPLOAD_FOLDER'] = 'static/uploads'
from flask.ext.mysqldb import MySQL app = MySQL() app.config['MYSQL_DATABASE_USER'] = '******' app.config['MYSQL_DATABASE_PASSWORD'] = '******' app.config['MYSQL_DATABASE_DB'] = 'database' app.config['MYSQL_DATABASE_HOST'] = 'localhost' mysql.init_app(app)
from flask import Flask, request from flask.ext.mysqldb import MySQL import json as jsonInstance import pandas as pandaInstance import requests as requestInstance app = Flask(__name__) # My SQL Server Configurations app.config['MYSQL_HOST'] = '127.0.0.1' app.config['MYSQL_USER'] = '******' app.config['MYSQL_PASSWORD'] = '******' app.config['MYSQL_DB'] = 'visualization' mysqlInstance = MySQL(app) @app.route('/getRecordsAsJSON') def getRecordsAsJSON(): # Get the input Parameter from the request Object inputSource = request.args.get('inputSource') jsonData = {} if inputSource == "database": # Create Connection and cursor instance cursorInstance = mysqlInstance.connection.cursor() # Prepared statement execution cursorInstance.execute('''SELECT * FROM IRIS''') # Extract the row headers / Metadata of the query rowMetadata = [x[0] for x in cursorInstance.description] # Fetch all the records resultset = cursorInstance.fetchall() json_data = []
from flask import Flask, render_template, request, redirect, abort, session, Blueprint from flask.ext.hashing import Hashing from flask.ext.mysqldb import MySQL from dateutil.relativedelta import relativedelta import time, datetime utils = Blueprint('utils', __name__) db = MySQL() #see if user is currently logged in def loggedIn(): return bool(session.get('id', False)) #get the election_id of the current election def getCurElection(): timestamp = getDBTimestamp(getCurTime()) #get today in mysql datetime format cur = db.connection.cursor() cur.execute("SELECT election_id FROM elections WHERE start_date <= %s AND end_date >= %s" + "ORDER BY end_date DESC LIMIT 1", [timestamp, timestamp]) result = cur.fetchall() election_ids = [] for eid in result: election_ids.append(eid) return election_ids #get the last election that is no longer accepting votes def getLastElection(): timestamp = getDBTimestamp(getCurTime()) #get today in mysql datetime format cur = db.connection.cursor()
import threading import time import os DEBUG = True application = Flask(__name__, instance_relative_config=True) application.config['MYSQL_USER'] = os.environ['RDS_USERNAME'] application.config['MYSQL_PASSWORD'] = os.environ['RDS_PASSWORD'] application.config['MYSQL_DB'] = os.environ['RDS_DB_NAME'] application.config['MYSQL_HOST'] = os.environ['RDS_HOSTNAME'] application.config.from_object(__name__) mysql = MySQL(application) def query_db(query, args=(), one=False, format=True, noresult=False): cur = mysql.connection.cursor() cur.execute(query, args) rv = cur.fetchall() if noresult: cur.close() return None else: if not format: cur.close() return (rv[0] if rv else None) if one else rv else: ret = (format_row(cur, rv[0]) if rv else None) if one else [format_row(cur, r) for r in rv] cur.close()
app = Flask(__name__) # Configurations app.config.from_object('config') # LoginManager # https://flask-login.readthedocs.org/en/latest/ # TODO: Validate next() login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = app.config["LOGIN_VIEW"] login_manager.login_message = app.config["LOGIN_MESSAGE"] login_manager.session_protection = app.config["SESSION_PROTECTION"] # Database db = MySQL(app) # ========================================= # Flask-restful # add prefix here or it won't work when you register blueprint # ========================================= api = Api(app, prefix=app.config["URL_PREFIX"]) @app.before_request def new_request(): print("New Request") print("############") @app.errorhandler(404)
# System imports import re, json # Third party imports import bleach, requests from flask import render_template, redirect, request, session from flask.ext.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 session.get('user'): return redirect('/discover') return render_template('index.html') @application.route('/register', methods=['GET', 'POST']) def register(): title = "Flixr - Register" if request.method == "GET": return render_template('register.html', title=title) elif request.method == "POST": try: # Request POST values and sanitise input of HTML where necessary _firstname = bleach.clean(request.form['inputFirstName'])