def init_db(): with closing(connect_db()) as db: with app.open_resource(DB_SCHEMA) as f: db.cursor().executescript(f.read()) setup(db) print_setup(db) default_users(db) db.commit()
def newdraft(name, team_names_and_emails, positions, rounds, players_filename): draftid = db.new_draft(name, positions, rounds, team_names_and_emails) if draftid: with app.open_resource(os.path.join('db', players_filename), mode='r') as f: data = [unicode(line, 'utf-8').split(',') for line in f.read().split('\n')] headings, data = data[0], data[1:] players = [dict(zip(headings, line)) for line in data] params = [(draftid, p['firstname'], p['surname'], p['searchable_name'], p['team'], p['position'], 0) for p in players] db.insert(sql='insert into players (draftid, firstname, surname, searchable_name, team, position, picked) values (?, ?, ?, ?, ?, ?, ?)', param_sets=params)
from __init__ import app, get_db with app.app_context(): db = get_db() with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit()
def get_resource_as_string(name, charset='utf-8'): with app.open_resource(name) as f: return f.read().decode(charset)
def init_db(): with closing(connect_db()) as db: with app.open_resource('schema.sql') as f: db.cursor().executescript(f.read()) db.commit()
def nfldraft(): "Create the NFL draft" with app.open_resource(os.path.join('db', 'nfl.json'), mode='r') as f: teams = json.loads(f.read()) newnfldraft('Necessary Roughness 2014', teams, 15, 2014)