Esempio n. 1
0
 def get_all_cards_with_colors(self, card_pool=None, colors='BW') -> dict:
     """
     :param card_pool: custom dictionary created from online json object
     :param colors: a combination of colors from magic the gathering
     :return:
     """
     ml.log_event(
         'get all cards that have at least color variation {}'.format(
             colors))
     cards_with_colors = dict()
     colors = _sanitize_colors(colors)
     if card_pool is None:
         ml.log_event('no card pool provided, using all cards')
         card_pool = self.all_cards
     else:
         ml.log_event(
             'card pool provided, starting with object of type {}'.format(
                 type(card_pool)))
     try:
         if not card_pool_is_dict(card_pool):
             raise TypeError
         for card_id in card_pool:
             card_color = \
                 _convert_list_of_strings_to_alphabetical_string(card_pool[card_id].get('colors'))
             if _card_contains_all_colors(card_color, colors):
                 ml.log_event('card id {} found with colors {}'.format(
                     card_id, colors))
                 cards_with_colors[card_id] = card_pool[card_id]
         return cards_with_colors
     except RuntimeError:
         raise RuntimeError
Esempio n. 2
0
 def get_top_count_ranked_cards(self, card_pool=None, count=500) -> dict:
     """
     :param card_pool: custom dictionary created from online json object
     :param count: the number of cards to fetch, each number corresponding to rank
     :return:
     """
     ml.log_event('searching for top {} ranked cards'.format(count))
     top_ranked_cards = dict()
     ranks_found = list()
     if card_pool is None:
         ml.log_event('no card pool provided, using all cards')
         card_pool = self.all_cards
     else:
         ml.log_event(
             'card pool provided, starting with object of type {}'.format(
                 type(card_pool)))
     try:
         if not card_pool_is_dict(card_pool):
             raise TypeError
         for card_id in card_pool.keys():
             if 'edhrecRank' in card_pool[card_id].keys():
                 edhrec_rank = card_pool[card_id].get('edhrecRank')
                 if 0 < edhrec_rank < count + 1:
                     if edhrec_rank not in ranks_found:
                         ml.log_event('card id {} found at rank {}'.format(
                             card_id, edhrec_rank))
                         ranks_found.append(edhrec_rank)
                         top_ranked_cards[card_id] = card_pool[card_id]
                         continue
         return top_ranked_cards
     except RuntimeError:
         raise RuntimeError
Esempio n. 3
0
 def get_all_cards_in_set(self, card_pool=None, set_name='Tempest') -> dict:
     """
     :param card_pool: custom dictionary created from online json object
     :param set_name: a set name from magic the gathering
     :return:
     """
     ml.log_event('get all cards belonging to set {}'.format(set_name))
     cards_in_set = dict()
     set_id = self._get_id_from_set_name(set_name)
     if card_pool is None:
         ml.log_event('no card pool provided, using all cards')
         card_pool = self.all_cards
     else:
         ml.log_event(
             'card pool provided, starting with object of type {}'.format(
                 type(card_pool)))
     try:
         if not card_pool_is_dict(card_pool):
             raise TypeError
         for card_id in card_pool:
             if set_id in card_id:
                 # TODO bug, false positive returns if card name contains set_id anywhere
                 ml.log_event('{} found for set_name {}'.format(
                     card_id, set_name))
                 cards_in_set[card_id] = card_pool[card_id]
         return cards_in_set
     except RuntimeError:
         raise RuntimeError
Esempio n. 4
0
 def get_all_cards_with_converted_mana_cost(self,
                                            card_pool=None,
                                            cmc=0) -> dict:
     """
     :param card_pool: custom dictionary created from online json object
     :param cmc: a 'total mana cost' from magic the gathering
     :return:
     """
     ml.log_event('getting all cards with cmc {}'.format(cmc))
     cards_with_cmc = dict()
     if card_pool is None:
         ml.log_event('no card pool provided, using all cards')
         card_pool = self.all_cards
     else:
         ml.log_event(
             'card pool provided, starting with object of type {}'.format(
                 type(card_pool)))
     try:
         if not card_pool_is_dict(card_pool):
             raise TypeError
         for card_id in card_pool.keys():
             mana_cost = process_mana_cost(
                 card_pool[card_id].get('manaCost'))
             if mana_cost == cmc:
                 ml.log_event('card {} found with cmc {}'.format(
                     card_id, cmc))
                 cards_with_cmc[card_id] = card_pool[card_id]
         return cards_with_cmc
     except RuntimeError:
         raise RuntimeError