Example #1
0
def admin_dashboard():
    bot_used, bot_total = get_bot_space()
    b_cap = 100 - (((float(bot_used or 0) / bot_total)) * 100)
    return render_template("admin/index.html",
        users_count=g.cursor.count("users"),
        games_count=g.cursor.count("games"),
        matches_count=g.cursor.count("matches"),
        bets_count=g.cursor.count("bets"),
        b_used=bot_used,
        b_total=bot_total,
        b_cap=b_cap)
Example #2
0
def route_match_bet(match_id):
    try:
        items = map(int, json.loads(request.values.get("items")))
        team = int(request.values.get("team"))
    except Exception as e:
        raise APIError("Invalid Request: %s" % e)

    # Make sure this seems mildly valid
    apiassert(0 < len(items) <= 4, "Too many items")

    match = g.cursor.select("matches",
        "id", "teams", "lock_date", "match_date", "public_date", "active",
        "max_value_item", "max_value_total",
    id=match_id).fetchone()

    itemvs = g.cursor.execute("SELECT id, name, price FROM items WHERE id IN %s", (tuple(items), )).fetchall(as_list=True)
    apiassert(len(itemvs) == len(items), "Invalid Item ID's")

    # Make sure we haven't bet too much shit
    if match.max_value_item:
        for item in itemvs:
            apiassert(item.price < match.max_value_item, "Price of item %s is too high!" % item.name)

    if match.max_value_total:
        apiassert(sum(map(lambda i: i.price, itemvs)) < match.max_value_total, "Total value placed is too high!")

    # Make sure we have a valid match
    apiassert(match, "Invalid match ID")
    apiassert(match.active, "Invalid match ID")
    apiassert(match.public_date.replace(tzinfo=None) < datetime.utcnow(), "Invalid match ID")
    apiassert(match.lock_date.replace(tzinfo=None) > datetime.utcnow(), "Match is locked")
    apiassert(len(match.teams) > team, "Invalid Team")

    # Make sure this user doesn't already have a bet on this match
    g.cursor.execute("SELECT * FROM bets WHERE better=%s AND match=%s", (g.user, match.id))
    apiassert(g.cursor.fetchone() == None, "Bet already created")

    # Ensure we have space for the items
    used, avail = get_bot_space()
    apiassert(avail > len(items), "No space left for bet")

    return APIResponse({
        "bet": create_bet(g.user, match_id, team, itemvs)
    })