<commit_before>from sqlalchemy import and_

from fantasydota.models import League, Hero, TeamHero, LeagueUser, Sale


def sell(session, user_id, hero_id, league_id):
    transfer_actually_open = session.query(League.transfer_open).filter(League.id == league_id).first()[0]
    if not transfer_actually_open:
        return {"success": False, "message": "Transfer window just open/closed. Please reload page"}

    l_user = session.query(LeagueUser).filter(LeagueUser.user_id == user_id).first()

    teamq = session.query(TeamHero).filter(and_(TeamHero.user_id == user_id,
                                                        TeamHero.league == league_id))

    user_money = l_user.money

    teamq_hero = session.query(TeamHero).filter(and_(TeamHero.user_id == user_id,
                                                     TeamHero.league == league_id))
    if teamq_hero.first():
        check_hero = teamq_hero.filter(and_(TeamHero.hero_id == hero_id))
        check_hero_res = check_hero.first()

        if check_hero_res:
            hero_value = session.query(Hero.value).filter(Hero.league == league_id).filter(Hero.id == hero_id).first()[0]
            new_credits = round(user_money + hero_value, 1)
            l_user.money = new_credits
            check_hero.delete()
            session.add(Sale(l_user.id, hero_id, league_id, hero_value, hero_value, False))
            return {"success": True, "message": "Hero successfully sold", "action": "sell", "hero": hero_id,
                    "new_credits": new_credits}
        else:
            return {"success": False, "message": "ERROR: Cannot sell, hero not in your team"}

    return {"success": False, "message": "Erm....you don't appear to be in this league. This is awkward"}


def buy(session, user_id, hero_id, league_id):
    transfer_actually_open = session.query(League.transfer_open).filter(League.id == league_id).first()[0]
    if not transfer_actually_open:<commit_msg>fix selling as well<commit_after>from sqlalchemy import and_

from fantasydota.models import League, Hero, TeamHero, LeagueUser, Sale


def sell(session, user_id, hero_id, league_id):
    transfer_actually_open = session.query(League.transfer_open).filter(League.id == league_id).first()[0]
    if not transfer_actually_open:
        return {"success": False, "message": "Transfer window just open/closed. Please reload page"}

    l_user = session.query(LeagueUser).filter(LeagueUser.user_id == user_id).filter(LeagueUser.league == league_id).first()

    teamq = session.query(TeamHero).filter(and_(TeamHero.user_id == user_id,
                                                        TeamHero.league == league_id))

    user_money = l_user.money

    teamq_hero = session.query(TeamHero).filter(and_(TeamHero.user_id == user_id,
                                                     TeamHero.league == league_id))
    if teamq_hero.first():
        check_hero = teamq_hero.filter(and_(TeamHero.hero_id == hero_id))
        check_hero_res = check_hero.first()

        if check_hero_res:
            hero_value = session.query(Hero.value).filter(Hero.league == league_id).filter(Hero.id == hero_id).first()[0]
            new_credits = round(user_money + hero_value, 1)
            l_user.money = new_credits
            check_hero.delete()
            session.add(Sale(l_user.id, hero_id, league_id, hero_value, hero_value, False))
            return {"success": True, "message": "Hero successfully sold", "action": "sell", "hero": hero_id,
                    "new_credits": new_credits}
        else:
            return {"success": False, "message": "ERROR: Cannot sell, hero not in your team"}

    return {"success": False, "message": "Erm....you don't appear to be in this league. This is awkward"}


def buy(session, user_id, hero_id, league_id):
    transfer_actually_open = session.query(League.transfer_open).filter(League.id == league_id).first()[0]
    if not transfer_actually_open:
{'fraction_non_alphanumeric': 0.11863117870722434, 'fraction_numerical': 0.0020278833967046894, 'mean_word_length': 2.9302788844621515, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5252338', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1162, 'n_words': 259}