Example #1
0
 def _get_playrates(self):
     playrate = card_collections.make_card_playset_dict()
     for deck in self.get_decks():
         for card in deck.cards:
             card_id = models_card.CardId(set_num=card.set_num,
                                          card_num=card.card_num)
             for num_played in range(min(card.num_played, 4)):
                 playrate[card_id][num_played] += self._scale_playrate(deck)
     return playrate
def get_card_ids_on_page_of_search(root_url: str,
                                   page: int) -> t.List[card_mod.CardId]:
    page_url = get_ew_cards_page_url(root_url=root_url, page=page)

    selector = ("div.card-search-results.row > div > div "
                "> table > tbody > tr > td:nth-child(1) > a")

    card_elements = browsers.get_elements_from_url_and_selector(
        url=page_url, selector=selector)
    card_ids = [
        card_mod.CardId(
            set_num=int(element.attrs["data-set"]),
            card_num=int(element.attrs["data-eternalid"]),
        ) for element in card_elements
    ]

    return card_ids
Example #3
0
        def add_cards_to_deck(deck: Deck, page_json: t.Dict):
            cards_json = (
                page_json["deck_cards"]
                + page_json["sideboard_cards"]
                + page_json["market_cards"]
            )

            for card_json in cards_json:
                set_num = card_json["set_number"]
                card_num = card_json["eternal_id"]
                card_id = card.CardId(set_num, card_num)

                # todo better to pass all_cards to this than use the global
                if global_data.all_cards.card_exists(card_id):
                    deck_has_card = DeckHasCard(
                        deck_id=page_json["deck_id"],
                        set_num=set_num,
                        card_num=card_num,
                        num_played=card_json["count"],
                    )
                    deck.cards.append(deck_has_card)
Example #4
0
def test_card_exists(all_cards):
    assert all_cards.card_exists(card_id=card.CardId(0, 0))
    assert not all_cards.card_exists(card_id=card.CardId(1, 0))
    assert not all_cards.card_exists(card_id=card.CardId(0, 3))
Example #5
0
 def to_card_id(self) -> card.CardId:
     return card.CardId(set_num=self.set_num, card_num=self.card_num)