Ejemplo n.º 1
0
def export_collection():
    c = Cards(db)
    collection = c.backup_collection()
    return Response(response=dumps(collection),
                    status=200,
                    mimetype="application/json")
Ejemplo n.º 2
0
def remove_card(card_id):
    c = Cards(db)
    return str(c.remove_owned(card_id))
Ejemplo n.º 3
0
def set_notes(card_id, notes):
    c = Cards(db)
    return str(c.set_notes(card_id, notes))
Ejemplo n.º 4
0
def cards():
    c = Cards(db)
    search = {}

    name = request.args.get("name", "")
    text = request.args.get("text", "")
    mana = request.args.get("mana", "")
    attack = request.args.get("attack", "")
    health = request.args.get("health", "")
    notes = request.args.get("notes", "")
    offset = request.args.get("offset", "")
    missing = request.args.get("missing", "")

    hero = request.args.getlist("hero")
    rarity = request.args.getlist("rarity")
    card_set = request.args.getlist("set")
    card_type = request.args.getlist("type")
    mechanics = request.args.getlist("mechanics")

    if name != "":
        search["name"] = name

    if text != "":
        search["text"] = text

    if len(hero) > 0:
        search["hero"] = hero

    if mana != "":
        search["cost"] = mana

    if attack != "":
        search["attack"] = attack

    if health != "":
        search["health"] = health

    if len(rarity) > 0:
        search["rarity"] = rarity

    if len(card_set) > 0:
        if "Standard" in card_set:
            search["card_format"] = "Standard"
        sets_only = [x for x in card_set if x != "Standard"]
        if len(sets_only) > 0:
            search["card_set"] = sets_only

    if len(card_type) > 0:
        search["card_type"] = card_type

    if len(mechanics) > 0:
        search["mechanics"] = mechanics

    if notes != "":
        search["notes"] = notes

    missing_cards = c.missing()

    if missing != "":
        cards = missing_cards[0]
    else:
        cards = c.search(**search)
    total = len(cards)

    if offset != "" and is_int(offset):
        offset = int(offset)
    else:
        offset = 0

    dust_needed = c.dust_needed()
    if len(dust_needed.keys()) > 0:
        packs = sorted(list(dust_needed.items()), key=lambda x: x[0])
        standard_packs = [x for x in packs if x[0] in config.standard_sets]
        buy_pack = sorted(standard_packs, key=lambda x: x[1], reverse=True)[0][0]
    else:
        packs = []
        buy_pack = None

    prev_offset = offset - config.card_limit
    if prev_offset < 0:
        prev_offset = 0
    next_offset = offset + config.card_limit
    if next_offset > total:
        next_offset = total - config.card_limit

    query = request.query_string.decode()
    prev_url = update_query_offset(query, prev_offset)
    next_url = update_query_offset(query, next_offset)

    args = {
        "cards": [format_card(x) for x in
                  cards[offset:offset + config.card_limit]],
        "heroes": ["Neutral"] + config.heroes,
        "rarities": [x.title() for x in c.rarities()],
        "card_sets": ["Standard"] + [x for x in c.sets()],
        "card_types": [x.title() for x in c.types()],
        "mechanics": [x.title() for x in c.mechanics()],
        "hero": hero,
        "name": name,
        "text": text,
        "mana": mana,
        "attack": attack,
        "health": health,
        "rarity": rarity,
        "card_set": card_set,
        "card_type": card_type,
        "mechanic": mechanics,
        "notes": notes,
        "offset": offset,
        "prev_url": prev_url,
        "next_url": next_url,
        "limit": config.card_limit,
        "current_page": int(offset / config.card_limit) + 1,
        "total_pages": int(total / config.card_limit) + 1,
        "prev_pages_left": offset > 0,
        "next_pages_left": offset + config.card_limit < total,
        "all_cards": c.total(),
        "total_ratio": winrate(c.total(), total),
        "card_image_url": config.card_image_url,
        "dust_needed": packs,
        "buy_pack": buy_pack,
        "total_missing": missing_cards[1],
        "total": total
    }

    return render_template("cards.html", **args)
Ejemplo n.º 5
0
def add_card(card_id):
    c = Cards(db)
    return str(c.add_owned(card_id))
Ejemplo n.º 6
0
def export_collection():
    c = Cards(db)
    collection = c.backup_collection()
    return Response(response=dumps(collection),
                    status=200,
                    mimetype="application/json")
Ejemplo n.º 7
0
def set_notes(card_id, notes):
    c = Cards(db)
    return str(c.set_notes(card_id, notes))
Ejemplo n.º 8
0
def remove_card(card_id):
    c = Cards(db)
    return str(c.remove_owned(card_id))
Ejemplo n.º 9
0
def add_card(card_id):
    c = Cards(db)
    return str(c.add_owned(card_id))
Ejemplo n.º 10
0
def cards():
    c = Cards(db)
    search = {}

    name = request.args.get("name", "")
    text = request.args.get("text", "")
    mana = request.args.get("mana", "")
    attack = request.args.get("attack", "")
    health = request.args.get("health", "")
    notes = request.args.get("notes", "")
    offset = request.args.get("offset", "")
    missing = request.args.get("missing", "")

    hero = request.args.getlist("hero")
    rarity = request.args.getlist("rarity")
    card_set = request.args.getlist("set")
    card_type = request.args.getlist("type")
    mechanics = request.args.getlist("mechanics")

    if name != "":
        search["name"] = name

    if text != "":
        search["text"] = text

    if len(hero) > 0:
        search["hero"] = hero

    if mana != "":
        search["cost"] = mana

    if attack != "":
        search["attack"] = attack

    if health != "":
        search["health"] = health

    if len(rarity) > 0:
        search["rarity"] = rarity

    if len(card_set) > 0:
        if "Standard" in card_set:
            search["card_format"] = "Standard"
        sets_only = [x for x in card_set if x != "Standard"]
        if len(sets_only) > 0:
            search["card_set"] = sets_only

    if len(card_type) > 0:
        search["card_type"] = card_type

    if len(mechanics) > 0:
        search["mechanics"] = mechanics

    if notes != "":
        search["notes"] = notes

    missing_cards = c.missing()

    if missing != "":
        cards = missing_cards[0]
    else:
        cards = c.search(**search)
    total = len(cards)

    if offset != "" and is_int(offset):
        offset = int(offset)
    else:
        offset = 0

    dust_needed = c.dust_needed()
    if len(dust_needed.keys()) > 0:
        packs = sorted(list(dust_needed.items()), key=lambda x: x[0])
        standard_packs = [x for x in packs if x[0] in config.standard_sets]
        buy_pack = sorted(standard_packs, key=lambda x: x[1],
                          reverse=True)[0][0]
    else:
        packs = []
        buy_pack = None

    prev_offset = offset - config.card_limit
    if prev_offset < 0:
        prev_offset = 0
    next_offset = offset + config.card_limit
    if next_offset > total:
        next_offset = total - config.card_limit

    query = request.query_string.decode()
    prev_url = update_query_string(query, "offset", prev_offset)
    next_url = update_query_string(query, "offset", next_offset)

    args = {
        "cards":
        [format_card(x) for x in cards[offset:offset + config.card_limit]],
        "heroes": ["Neutral"] + config.heroes,
        "rarities": [x.title() for x in c.rarities()],
        "card_sets": ["Standard"] + [x for x in c.sets()],
        "card_types": [x.title() for x in c.types()],
        "mechanics": [x.title() for x in c.mechanics()],
        "hero": hero,
        "name": name,
        "text": text,
        "mana": mana,
        "attack": attack,
        "health": health,
        "rarity": rarity,
        "card_set": card_set,
        "card_type": card_type,
        "mechanic": mechanics,
        "notes": notes,
        "offset": offset,
        "prev_url": prev_url,
        "next_url": next_url,
        "limit": config.card_limit,
        "current_page": int(offset / config.card_limit) + 1,
        "total_pages": int(total / config.card_limit) + 1,
        "prev_pages_left": offset > 0,
        "next_pages_left": offset + config.card_limit < total,
        "all_cards": c.total(),
        "total_ratio": winrate(c.total(), total),
        "card_image_url": config.card_image_url,
        "dust_needed": packs,
        "buy_pack": buy_pack,
        "total_missing": missing_cards[1],
        "total": total
    }

    return render_template("cards.html", **args)