def _parse_deck(deck): for key, value in deck['commanders'].items(): yield Card(key, value['quantity'], tags=['commander']) for key, value in deck['companions'].items(): yield Card(key, value['quantity'], tags=['companion']) for key, value in deck['mainboard'].items(): yield Card(key, value['quantity'])
def _parse_deck(deck): soup = BeautifulSoup(deck, features='html.parser') for subdeck in soup.find_all('div', class_='subdeck'): subdeck_name = next( subdeck.find('h3', class_='subdeck__name').stripped_strings) for group in subdeck.find_all('div', class_='subdeck-group'): group_name = group.find('h4', class_='subdeck-group__name') if group_name: group_name = next(group_name.stripped_strings) tags = list(_get_tags(subdeck_name, group_name)) for card in group.find_all('a', class_='subdeck-group__card'): name = (card.find( 'span', class_='subdeck-group__card-name').get_text(strip=True)) quantity = (card.find( 'span', class_='subdeck-group__card-qty').get_text(strip=True)) yield Card( name, quantity, tags=tags, )
def _parse_deck(deck): for section in deck.get('sections', []): for card in section.get('cards', {}): yield Card( card['name'], card['amount'], tags=_get_tags(card), )
def _to_card(line): return Card( line.get('card_name'), line.get('quantity'), line.get('extension'), line.get('collector_number'), line.get('tags'), )
def _parse_deck(deck): categories = deck['categories'] categories = filter(lambda c: c.get('includedInDeck', False), categories) categories = map(lambda c: c['name'], categories) categories = set(categories) for card in deck['cards']: if categories.intersection(card['categories']): yield Card( card['card']['oracleCard']['name'], card['quantity'], card['card']['edition']['editioncode'], card['card'].get('collectorNumber'), card['categories'] )
def _parse_deck(deck): last_category = None for entry in deck.get('convertedDeck', []): quantity = entry.get('quantity') name = entry.get('name') extension = entry.get('set') number = entry.get('number') if not quantity: last_category = name elif name and quantity: if last_category: tags = [last_category] card = Card(name, quantity, extension, number, tags) yield card
def _parse_deck(deck): soup = BeautifulSoup(deck, features='html.parser') soup = soup.find('table', class_='deck-view-deck-table') soup = soup.find_all('tr', recursive=False) last_category = None for row in soup: if 'deck-category-header' in row.attrs.get('class', []): last_category = row.th.string.strip().splitlines()[0].lower() else: yield Card( row.a.string.strip(), row.td.string.strip(), re.search(r'\[(.*?)\]', row.a.attrs.get('data-card-id')).group(1).lower(), tags=[last_category], )
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests_mock import pytest import mtg_parser from mtg_parser.card import Card from .utils import mock_response @pytest.mark.parametrize('deck1,deck2', [ [ [ Card('Brainstorm'), Card('Portent'), Card('Ponder'), ], [ Card('Portent'), Card('Ponder'), Card('Opt'), ], ], ]) def test_diff(deck1, deck2): result = mtg_parser.diff(deck1, deck2) for _, value in result.items(): assert value and all(value)