def botInventory(self): Session = db.sessionmaker(bind=db.engine)() RBot = Session.query(db.Bots).filter(db.Bots.id == self.Bot.id).first() inventory, slots = self.Bot.Community().inventory() if inventory: RBot.slots = slots["total"] RBot.slotsEmpty = slots["empty"] self.Meta = RBot.to_dict() Session.commit() Session.close() return inventory, slots
def userInventory(self, userID): Session = db.sessionmaker(bind=db.engine)() RUser = Session.query(db.Users).filter(db.Users.id == userID).first() Partner = self.Bot.Community().Friend(RUser.steamID) Partner.token = RUser.token inventory, slots = Partner.inventory() if inventory: RUserInventory = Session.query(db.UsersInventories).filter(db.UsersInventories.user == userID).first() RUserInventory.inventory = inventory Session.commit() Session.close() return inventory, slots
import os from flask import Flask from flask_sqlalchemy import SQLAlchemy import settings from database import engine, sessionmaker import logging conf = settings.Configure() logging.basicConfig(filename=conf.LOG_NAME, level=conf.LOG_LEVEL, format='%(asctime)s %(message)s') logging.debug('*** Starting {0}'.format(conf.BLOG_NAME)) app = Flask(__name__) # app.config["SQLALCHEMY_DATABASE_URI"] = conf.database_connection_string app.logger.info('myLogger: setting 1') app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL'] app.logger.info('myLogger: setting 2') app.config["SECRET_KEY"] = conf.secret_key app.logger.info('myLogger: setting 3') db = SQLAlchemy(app) app.logger.info('myLogger: setting 4') DBSession = sessionmaker(bind=engine) import views