Exemplo n.º 1
0
    def extract(self):
        cards = []

        for component in self.document.cssselect('td.cardComponentContainer'):
            if not component.getchildren():
                continue  # do not parse empty components
            labels = component.cssselect('div.label')
            values = component.cssselect('div.value')
            pairs = zip(labels, values)
            card = Card()
            attributes = {}
            for (label, value) in pairs:
                attr = label.text_content().strip(': \n\r') \
                    .replace(' ', '_').lower()
                attr = attribute_map.get(attr) or attr
                if attr == 'p/t':
                    attributes['power'], attributes['toughness'] = \
                        self.pow_tgh(value)
                elif attr == 'rules_text':
                    attributes[attr] = self.box_field(value, 'div.cardtextbox',
                                                      ' ; ')
                elif attr == 'printings':
                    attributes[attr] = self.printings(value, 'img')
                    attributes['printings_full'] = self.printings(value,
                                                                  'img',
                                                                  full=True)
                elif attr == 'rarity':
                    continue
                elif attr == 'flavor_text':
                    attributes[attr] = self.box_field(value,
                                                      'div.flavortextbox',
                                                      '\n')
                elif attr == 'mana_cost':
                    attributes[attr] = self.symbol_field(value, 'img')
                elif attr == 'types':
                    attributes['types'], attributes['subtypes'] = self.types(
                        value.text_content().strip())
                elif attr == 'community_rating':
                    attributes['community_rating'] = self.text_field(
                        value, 'span.textRatingValue')
                    attributes['community_votes'] = self.text_field(
                        value, 'span.totalVotesValue')
                else:
                    attributes[attr] = value.text_content().strip()

            for a, v in attributes.items():
                if is_string(v):
                    v = clean_dashes(v)
                setattr(card, a, v)
            for ruling in component.cssselect('tr.post'):
                date, text = ruling.cssselect('td')
                card.ruling_data.append(
                    (date.text_content(), text.text_content()))
            cards.append(card)
        return cards
Exemplo n.º 2
0
 def setUp(self):
     self.card = Card()
     self.card.name = u'Name'
     self.card.mana_cost = u'2UUU'
     self.card.types = [u'Legendary', u'Creature']
     self.card.subtypes = [u'Human', u'Wizard']
     self.card.power = 3
     self.card.toughness = 4
     self.card.rules_text = u'Rules Text (This is just an example.)'
     self.card.flavor_text = u'"Flavor text"'
     self.card.printings = [(u'Time Spiral', u'Rare')]
     self.card.ruling_data = [(u'9/25/2006', u'Ruling Text'),
                              (u'9/25/2006', u'Ruling Two')]
Exemplo n.º 3
0
    def extract_many(self):
        cards = []
        for card_item in self.document.cssselect('.cardItem'):
            card = Card()
            cardinfo = card_item.cssselect('.cardInfo')[0]
            card.name = self.text_field(cardinfo, '.cardTitle')
            card.mana_cost = self.symbol_field(cardinfo, '.manaCost img')
            card.rules_text = self.box_field(cardinfo, '.rulesText p', '\n')

            typeline = self.text_field(cardinfo, '.typeLine')
            if '(' in typeline:
                typeline, number = typeline.rsplit(' ', 1)
                number = number.strip('()')
                if number.isnumeric():
                    card.loyalty = number
                else:
                    card.power, card.toughness = self.split_pow_tgh(number)
            card.types, card.subtypes = self.types(typeline.strip('\n '))
            setinfo = card_item.cssselect('.setVersions')[0]
            card.printings = self.printings(setinfo, 'img')
            card.printings_full = self.printings(setinfo, 'img', full=True)
            cards.append(card)
        return cards
Exemplo n.º 4
0
    def extract_many(self):
        cards = []

        for item in self.document.cssselect('tr.cardItem'):
            for c in item.cssselect('div.cardInfo'):
                card = Card()
                card.name = self.text_field(c, '.cardTitle')
                card.mana_cost = self.symbol_field(c, '.manaCost img')
                typeline = self.text_field(c, '.typeLine')
                t = [l.strip() for l in typeline.split('\n') if l.strip()]
                card.types = t.pop(0)
                if t:
                    number = t.pop(0).strip('()')
                    if '/' in number:
                        card.power, card.toughness = number.split('/')
                    else:
                        card.loyalty = number
                card.types = clean_dashes(card.types)
                card.rules_text = self.box_field(c, 'div.rulesText p', ' ; ')
                card.printings = self.printings(item, 'td.rightCol img')
            cards.append(card)
        return cards
Exemplo n.º 5
0
    def extract_many(self):
        cards = []
        for card_item in self.document.cssselect('.cardItem'):
            card = Card()
            cardinfo = card_item.cssselect('.cardInfo')[0]
            card.name = self.text_field(cardinfo, '.cardTitle')
            card.mana_cost = self.symbol_field(cardinfo, '.manaCost img')
            card.rules_text = self.box_field(cardinfo, '.rulesText p', '\n')

            typeline = self.text_field(cardinfo, '.typeLine')
            if '(' in typeline:
                typeline, number = typeline.rsplit(' ', 1)
                number = number.strip('()')
                if number.isnumeric():
                    card.loyalty = number
                else:
                    card.power, card.toughness = self.split_pow_tgh(number)
            card.types, card.subtypes = self.types(typeline.strip('\n '))
            setinfo = card_item.cssselect('.setVersions')[0]
            card.printings = self.printings(setinfo, 'img')
            card.printings_full = self.printings(setinfo, 'img', full=True)
            cards.append(card)
        return cards
Exemplo n.º 6
0
 def should_correctly_pluralize_results(self):
     cardlist = CardList([Card(), Card(), Card()])
     self.assertEqual(cardlist.num_results(), '\n3 results found.')
Exemplo n.º 7
0
 def should_correctly_singularize_results(self):
     cardlist = CardList([Card()])
     self.assertEqual(cardlist.num_results(), '\n1 result found.')
Exemplo n.º 8
0
    def setUp(self):
        card1 = Card()
        card1.name = u'Name'
        card1.mana_cost = u'2UUU'
        card1.types = [u'Legendary', u'Creature']
        card1.subtypes = [u'Human', u'Wizard']
        card1.power = 3
        card1.toughness = 4
        card1.rules_text = u'Rules Text (This is just an example.)'
        card1.flavor_text = u'"Flavor text"'
        card1.printings = [(u'Time Spiral', u'Rare')]
        card1.ruling_data = [(u'9/25/2006', u'Ruling Text'),
                             (u'9/25/2006', u'Ruling Two')]
        card2 = Card()
        card2.name = u'Worldspine Wurm'
        card2.mana_cost = u'8GGG'
        card2.types = [u'Creature']
        card2.subtypes = [u'Wurm']
        card2.power = 15
        card2.toughness = 15
        card2.rules_text = u'Trample ; When Worldspine Wurm dies, put three 5/5 green Wurm creature tokens with trample onto the battlefield. ; When Worldspine Wurm is put into a graveyard from anywhere, shuffle it into its owner\'s library.'
        card2.printings = [(u'Return to Ravnica', u'Mythic Rare')]

        self.cards = [card1, card2]
Exemplo n.º 9
0
    def setUp(self):
        card1 = Card()
        card1.name = u'Name'
        card1.mana_cost = u'2UUU'
        card1.types = [u'Legendary', u'Creature']
        card1.subtypes = [u'Human', u'Wizard']
        card1.power = 3
        card1.toughness = 4
        card1.rules_text = u'Rules Text (This is just an example.)'
        card1.flavor_text = u'"Flavor text"'
        card1.printings = [(u'Time Spiral', u'Rare')]
        card1.ruling_data = [(u'9/25/2006', u'Ruling Text'),
                             (u'9/25/2006', u'Ruling Two')]
        card2 = Card()
        card2.name = u'Worldspine Wurm'
        card2.mana_cost = u'8GGG'
        card2.types = [u'Creature']
        card2.subtypes = [u'Wurm']
        card2.power = 15
        card2.toughness = 15
        card2.rules_text = u'Trample ; When Worldspine Wurm dies, put three 5/5 green Wurm creature tokens with trample onto the battlefield. ; When Worldspine Wurm is put into a graveyard from anywhere, shuffle it into its owner\'s library.'
        card2.printings = [(u'Return to Ravnica', u'Mythic Rare')]

        self.cards = [card1, card2]