from flask import Flask
from flask.ext.mysqldb import MySQL

app = Flask(__name__)
app.config["MYSQL_HOST"] = "sql3.freemysqlhosting.net"
app.config["MYSQL_USER"] = "yourusername"
app.config["MYSQL_PASSWORD"] = "mypassword"
app.config["MYSQL_DB"] = "yourdatabasename"
mysql = MySQL(app)


@app.route("/")
def index():
    cur = mysql.connection.cursor()
    cur.execute("""SELECT data FROM example WHERE id = 1""")
    rv = cur.fetchall()
    return str(rv)


if __name__ == "__main__":
    app.run(debug=True)
Beispiel #2
0
""" ""


from flask import Flask
from flask import render_template
from flask import jsonify
from flask.ext.mysqldb import MySQL


app = Flask(__name__)
mysql = MySQL(app)

app.config["MYSQL_HOST"] = "localhost"
app.config["MYSQL_PORT"] = 3306
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "2197832"
app.config["MYSQL_DB"] = "sakonwaba"


@app.route("/")
def main():
    return render_template("index.html")


def sakonwaba():
    cur = mysql.connection.cursor()
    cur.execute("SELECT * FROM products")
    cur.execute("SELECT * FROM products")
    productsResults = [dict(name=row[1]) for row in cur.fetchall()]

    return jsonify(productsResults=productsResults)
Beispiel #3
0
from flask import Flask, redirect, request  # ,session
import json
import random
from flask.ext.mysqldb import MySQL

app = Flask("MS_Hack")
mysql = MySQL()

app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "narcos"
app.config["MYSQL_DB"] = "mshack"
app.config["MYSQL_HOST"] = "localhost"
app.config["MYSQL_PORT"] = 3306
mysql.init_app(app)
gid = ""


@app.route("/", methods=["GET", "POST"])
def index():
    cur = mysql.connection.cursor()
    cur.execute("select * from leader;")
    rv = cur.fetchall()
    print str(rv)
    return "Hello World"


# @app.route('/val')
# def insert():
#     cur=mysql.connection.cursor()
#     cur.execute("insert into member values(%s,%s,%s,%s,%s)",(1,'name','123.4','123.4',0))
#     mysql.connection.commit()
Beispiel #4
0
# Out config
import consts
from config import kMySQLSettings

# Utilities
from util import genMarkdownResult


## Web app config
app = Flask(__name__)
app.config["DEBUG"] = consts.DEBUG_APP

# Database connection
app.config["MYSQL_HOST"] = kMySQLSettings["host"]
app.config["MYSQL_USER"] = kMySQLSettings["user"]
app.config["MYSQL_PASSWORD"] = kMySQLSettings["pwd"]
app.config["MYSQL_DB"] = kMySQLSettings["dbname"]
app.config["MYSQL_PORT"] = kMySQLSettings["port"]
app.config["MYSQL_USE_UNICODE"] = True
app.config["MYSQL_CHARSET"] = "utf8"

# Cache DB connection factory in global
app.config["DBCONN"] = MySQL(app)

# Pretty print JSON responses only if debugging
app.config["JSONIFY_PRETTYPRINT_REGULAR"] = consts.DEBUG_APP


# Routes in other modules
import permits, neighborhoods, taxlots, crimes, census, demolitions
Beispiel #5
0
def mysql_test():
    cur = mysql.connection.cursor()
    cur.execute("""SELECT * FROM user""")
    rv = cur.fetchall()
    return str(rv)


@app.errorhandler(404)
def page_not_found(e):
    return "Page not found"


if __name__ == "__main__":
    app.debug = True
    app.secret_key = "\xc2ogq\xe9\x957*\x12\xabA\nR\x84NY*\x94\xc6;\\\xfa\x13\xf7"

    # logging
    handler = RotatingFileHandler("error.log", maxBytes=10000, backupCount=1)
    handler.setLevel(logging.INFO)
    app.logger.addHandler(handler)

    # mysql
    mysql = MySQL()
    app.config["MYSQL_USER"] = "root"
    app.config["MYSQL_PASSWORD"] = "Pwn210577"
    app.config["MYSQL_HOST"] = "127.0.0.1"
    app.config["MYSQL_DB"] = "my_flask_app"
    mysql.init_app(app)

    # run app
    app.run()
#!/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"] = "bhtan"
app.config["MYSQL_PASSWORD"] = "bacon123"
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
Beispiel #7
0
from flask import Flask
from flask.ext.mysqldb import MySQL

app = Flask(__name__)
mysql = MySQL()
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "nike27"
mysql.init_app(app)


@app.route("/helloworld")
def hello():
    cur = mysql.connection.cursor()
    cur.execute("""SELECT * FROM helloworld.messages""")
    msgs = cur.fetchall()
    return str(msgs)


if __name__ == "__main__":
    app.run("0.0.0.0")
from flask.ext.mysqldb import MySQL
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash

app = Flask(__name__)
mysql = MySQL(app)

app.config["MYSQL_HOST"] = "localhost"
app.config["MYSQL_PORT"] = 3306
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "951022"
app.config["MYSQL_DB"] = "my_products"


@app.route("/")
def prodList():
    cur = mysql.connection.cursor()
    cur.execute("""SELECT Id,Name from Products""")
    entries = [dict(Id=row[0], Name=row[1]) for row in cur.fetchall()]

    cur.execute(
        """SELECT SUM(Qty) AS TotalQty , Product_Id, Name from Sales s INNER JOIN Products p ON s.Product_Id = p.Id 					GROUP BY Name"""
    )
    products = [dict(Name=row[2], Qty=row[0]) for row in cur.fetchall()]

    cur.execute("""SELECT Id,Name from Categories""")
    categories = [dict(Id=row[0], Name=row[1]) for row in cur.fetchall()]

    cur.execute(
        """SELECT  Categories.Name, sum(Sales.Qty) AS TotalQty from Sales INNER JOIN Products ON Sales.Product_id = Products.Id INNER JOIN Categories ON Products.Category_id = Categories.Id GROUP BY Categories.Name"""
    )
    cats = [dict(Name=row[0], Qty=row[1]) for row in cur.fetchall()]
Beispiel #9
0
from flask import Flask, render_template, request
from flask.ext.mysqldb import MySQL
from event import Event
import time, datetime
import json
import os
import psycopg2
import urlparse


app = Flask(__name__)
app.debug = True

# MySQL configurations
app.config["MYSQL_USER"] = "b6d4aa52f18aa3"
app.config["MYSQL_PASSWORD"] = "0580749d"
app.config["MYSQL_DB"] = "heroku_3d39916556b689d"
app.config["MYSQL_HOST"] = "us-cdbr-iron-east-03.cleardb.net"
mysql = MySQL(app)


"""
#postgres config
urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse(os.environ["DATABASE_URL"])

conn = psycopg2.connect(
  database=url.path[1:],
  user=url.username,
  password=url.password,
  host=url.hostname,
Beispiel #10
0
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"] = "root"
application.config["MYSQL_PASSWORD"] = "pythondev"
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"
application.config["MAX_CONTENT_LENGTH"] = 10 * 1024 * 1024
ALLOWED_EXTENSIONS = set(["jpg"])

# Check the uploads folder exists, otherwise create it
print("INFO: Checking if upload folder exists")
if not os.path.exists(application.config["UPLOAD_FOLDER"]):
    try:
        print("WARN: Upload folder does not exist, creating it")
        os.makedirs(application.config["UPLOAD_FOLDER"])
Beispiel #11
0
from flask import Flask
from flask.ext.mysqldb import MySQL

app = Flask(__name__)
mysql = MySQL()
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "941103"
mysql.init_app(app)


@app.route("/helloworld")
def hello():
    cur = mysql.connection.cursor()
    cur.execute("SELECT * FROM helloworld.messages")
    msgs = cur.fetchall()
    return str(msgs)


if __name__ == "__main__":
    app.run()
Beispiel #12
0
# -*- coding: UTF-8 -*-
from flask import Flask, render_template, request
from flask.ext.mysqldb import MySQL
import socket

mysql = MySQL()

app = Flask(__name__)

app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "123456"
app.config["MYSQL_DB"] = "demoapp"
app.config["MYSQL_HOST"] = "db.inet"

# app.config['MYSQL_DATABASE_USER'] = 'root'
# app.config['MYSQL_DATABASE_PASSWORD'] = '123456'
# app.config['MYSQL_DATABASE_DB'] = 'demoapp'
# app.config['MYSQL_DATABASE_HOST'] = 'db'

mysql.init_app(app)


@app.route("/")
def main():

    hostname = socket.gethostname()
    ipaddr = socket.gethostbyname(hostname)

    cursor = mysql.connection.cursor()
    cursor.execute("select count(*) as qtde from subscription")
    query = cursor.fetchone()
# some bits of text for the page.
header_text = """
    <html>\n<head> <title>EB Flask Test</title> </head>\n<body>"""
instructions = """
    <p><em>Hint</em>: This is a RESTful web service! Append a username
    to the URL (for example: <code>/Thelonious</code>) to say hello to
    someone specific.</p>\n"""
home_link = '<p><a href="/">Back</a></p>\n'
footer_text = "</body>\n</html>"

# EB looks for an 'application' callable by default.
application = Flask(__name__)

# setup mysql connection
application.config["MYSQL_USER"] = "BDR"
application.config["MYSQL_PASSWORD"] = "BDRforlife"
application.config["MYSQL_HOST"] = "bdr.c7uzpeqksgw0.eu-central-1.rds.amazonaws.com"
application.config["MYSQL_PORT"] = 3306
application.config["MYSQL_DB"] = "BDR"
mysql = MySQL(application)

# add a rule for the index page.
application.add_url_rule("/", "index", (lambda: header_text + say_hello() + instructions + footer_text))

# add a rule when the page is accessed with a name appended to the site
# URL.
application.add_url_rule(
    "/<username>", "hello", (lambda username: header_text + say_hello(username) + home_link + footer_text)
)

Beispiel #14
0
from flask import Flask
from flask.ext.mysqldb import MySQL

app = Flask(__name__)
mysql = MySQL()
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "DHGLYjoe521"
mysql.init_app(app)


@app.route("/helloworld")
def hello():
    cur = mysql.connection.cursor()
    cur.execute("SELECT * from helloworld.messages")
    msgs = cur.fetchall()
    return str(msgs)


if __name__ == "__main__":
    app.run()
Beispiel #15
0
from flask.ext.mysqldb import MySQL
from flask.ext.bcrypt import Bcrypt
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash

app = Flask(__name__)
bcrypt = Bcrypt(app)
app.config.from_object(__name__)

app.secret_key = "d4rthV4d3rIsYourF4th3r"

mysql = MySQL(app)
app.config["MYSQL_HOST"] = "localhost"
app.config["MYSQL_PORT"] = 3306
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = "coder123"
app.config["MYSQL_DB"] = "nelisaFlask"
# 	app.config['MYSQL_CHARSET'] = 'utf-8'


@app.route("/")
def show_landing():
    if session:
        return redirect(url_for("show_menu"))
    else:
        return render_template("land.html")


@app.route("/signUp", methods=["GET", "POST"])
def signUp():
    if request.method == "POST":
        if request.form["password"] == request.form["password2"]:
Beispiel #16
0
# -*- coding: utf-8 -*-
from flask import Flask, request, render_template
from flask.ext.mysqldb import MySQL
from models import *


app = Flask(__name__)
mysql = MySQL(app)
app.config["MYSQL_USER"] = "root"
app.config["MYSQL_PASSWORD"] = ""
app.config["MYSQL_DB"] = "bigdatasystem"
app.config["MYSQL_HOST"] = "127.0.0.1"


def getMarjorRank(schools, ratio, character):

    cur = mysql.connection.cursor()

    cur.execute("set names utf8")
    majorLists = []
    for school in schools:

        # 求出学校的平均水平
        sqlStr = "select rank from school where schoolId=%d" % (school.schoolId)
        cur.execute(sqlStr)
        schoolResult = cur.fetchall()
        school.rank = schoolResult[0][0]
        sqlStr = "select * from major where schoolId=%d" % (school.schoolId)
        cur.execute(sqlStr)
        results = cur.fetchall()
        # 求每个major的评价
Beispiel #17
0
# -*- coding: utf-8 -*-
from flask import Flask, render_template, redirect, url_for
from flask.ext.mysqldb import MySQL

app = Flask(__name__)
app.config["MYSQL_DB"] = "mybaseball"
app.config["MYSQL_USER"] = "guest"
app.config["MYSQL_PASSWORD"] = "aOVG1L2xDC"
app.config["MYSQL_HOST"] = "localhost"
mysql = MySQL(app)
charset = "utf-8"
object_type_list = ["league", "team", "game", "player"]


def get_table(object_type, id_num, where_string="TRUE"):
    where_string = where_string.encode(charset)
    cur = mysql.connection.cursor()
    cur.execute("USE mybaseball")
    tables = []
    if id_num == 0:
        description = ("No", " ", "Data")
    elif object_type == object_type_list[0]:

        query = "SELECT league_year, league_name FROM league WHERE league_id = %d" % id_num
        cur.execute(query)
        description = cur.fetchall()

        query = "CALL load_rank_table(%d)" % id_num
        cur.execute(query)
        table = {
            "index": [
Beispiel #18
0
from flask import Flask
from flask import render_template
from flask import request
import jinja2
from flask.ext.mysqldb import MySQL

app = Flask(__name__)
mysql = MySQL()
app.config["MYSQL_USER"] = "it2216"
app.config["MYSQL_HOST"] = "cs4111.caxmabhvo5cr.us-west-2.rds.amazonaws.com"
app.config["MYSQL_PASSWORD"] = "kimtorras"
app.config["MYSQL_DB"] = "cs4111"
mysql.init_app(app)


@app.route("/")
@app.route("/<search>")
def index(search=None):
    cuisines = mysql.connect.cursor()
    cuisines.execute("SELECT DISTINCT cuisine FROM Restaurants;")
    cuisines = cuisines.fetchall()

    zip_codes = mysql.connect.cursor()
    zip_codes.execute("SELECT DISTINCT zip FROM Addresses;")
    zip_codes = zip_codes.fetchall()

    ratings = [2.0, 3.0, 4.0, 5.0]

    restaurant = request.args.get("restaurant")
    cuisine = request.args.get("cuisine")
    zipcode = request.args.get("zipcode")
Beispiel #19
0
from flask import Flask
from flask.ext.mysqldb import MySQL

app = Flask(__name__)

app.config["MYSQL_USER"] = "myungchan"
app.config["MYSQL_PASSWORD"] = "dbgood"
app.config["MYSQL_DB"] = "myungchan"
app.config["MYSQL_HOST"] = "10.73.38.158"
mysql = MySQL(app)


@app.route("/")
def test():
    cur = mysql.connection.cursor()
    result_header = """
    <body>
        <h1> Next Student List </h1>
        <ul>
    """
    result_tail = """
        </ul>
    </body>
    """

    result_body = ""
    row_header = "<li>"
    row_tail = "</li>"

    cur.execute("USE myungchan")
    cur.execute(