def import_sample_recipe_and_grocery(): """ Made into a function to avoid polluting global scope :return: """ connection = IGDBConnector.connect() grab_recipe_data(connection) generate_fake_grocery_data(connection) generate_recipe_prices(connection) connection.close()
from flask import Flask, request, render_template, redirect, url_for from db.igdb_connector import IGDBConnector from mysql.connector import errors import flask_login from flask.ext.login import UserMixin app = Flask(__name__) login_manager = flask_login.LoginManager() login_manager.init_app(app) # Creates a global connection to the database conn = IGDBConnector.connect() class User(UserMixin): """ A simple User class with the username being the id. """ def __init__(self, name): self.name = name self.id = name @login_manager.user_loader def load_user(user_id): cur = conn.cursor() cur.execute("SELECT * FROM users WHERE username = %s", (user_id,)) r = cur.fetchone() return User(r[0]) if r is not None else None