def update_items(db): items = riot_api.get_items() for item in items: item_data = items[item] gold = item_data['gold'] db.execute('insert into items (id, name, img_url, base_cost, full_cost) values (?, ?, ?, ?, ?)', [item, item_data['name'], item_data['image']['full'], gold['base'], gold['total']])
def update_items(db): items = riot_api.get_items() for item in items: item_data = items[item] gold = item_data['gold'] db.execute( 'insert into items (id, name, img_url, base_cost, full_cost) values (?, ?, ?, ?, ?)', [ item, item_data['name'], item_data['image']['full'], gold['base'], gold['total'] ])
def init_db(): with closing(connect_db()) as db: with app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) items = riot_api.get_items() for item in items: item_data = items[item] gold = item_data['gold'] db.execute('insert into items (id, name, img_url, base_cost, full_cost) values (?, ?, ?, ?, ?)', [item, item_data['name'], item_data['image']['full'], gold['base'], gold['total']]) champions = riot_api.get_champions() for champ in champions: id = int(champions[champ]['key']) img_url = champions[champ]['image']['full'] db.execute('insert into champions (id, img_url) values (?, ?)', [id, img_url]) db.commit()
from sqlalchemy.sql import select from datetime import datetime, timedelta import riot_api import pickle import os # Set up sqlite3 with sqlalchemy engine = create_engine('sqlite:///data.db') Base = declarative_base() Session = sessionmaker() Session.configure(bind=engine) # Get champion data from the api champions = riot_api.get_champions() # Get item data from the api items = riot_api.get_items() class Match(Base): """ Schema for Matches """ __tablename__ = 'matches' match_id = Column(Integer, primary_key=True) region = Column(String) created_on = Column(DateTime) duration = Column(Interval) version = Column(String, index=True) items_bought = relationship("BoughtItems") def __repr__(self): s = "<match_id={0}, region={1}, created_on={2}, duration={3}>"