Esempio n. 1
0
async def background_task_spoiler_season():
    "Poll Scryfall for the latest 250 cards, and add them to our db if missing"
    await BOT.client.wait_until_ready()
    new_cards = fetcher.scryfall_cards()
    for c in new_cards['data']:
        try:
            oracle.valid_name(c['name'])
        except InvalidDataException:
            oracle.insert_scryfall_card(c)
            print('Imported {0} from Scryfall'.format(c['name']))
Esempio n. 2
0
async def background_task_spoiler_season() -> None:
    'Poll Scryfall for the latest 250 cards, and add them to our db if missing'
    await BOT.client.wait_until_ready()
    new_cards = await fetcher.scryfall_cards_async()
    for c in new_cards['data']:
        try:
            oracle.valid_name(c['name'])
            await asyncio.sleep(1)
        except InvalidDataException:
            oracle.insert_scryfall_card(c, True)
            print('Imported {0} from Scryfall'.format(c['name']))
            await asyncio.sleep(5)
        except TooFewItemsException:
            pass
Esempio n. 3
0
 async def background_task_spoiler_season(self) -> None:
     'Poll Scryfall for the latest 250 cards, and add them to our db if missing'
     latest_cards = await fetcher.scryfall_cards_async()
     cards_not_currently_in_db: List[CardDescription] = []
     for c in latest_cards['data']:
         name = multiverse.name_from_card_description(c)
         try:
             oracle.valid_name(name)
         except InvalidDataException:
             print(
                 f'Planning to add {name} to database in background_task_spoiler_season.'
             )
             cards_not_currently_in_db.append(c)
     if len(cards_not_currently_in_db) > 0:
         oracle.add_cards_and_update(cards_not_currently_in_db)
Esempio n. 4
0
def card(name):
    try:
        c = cs.load_card(oracle.valid_name(urllib.parse.unquote_plus(name)), season_id=get_season_id())
        view = Card(c)
        return view.page()
    except InvalidDataException as e:
        raise DoesNotExistException(e)
Esempio n. 5
0
def card(name):
    try:
        c = cs.load_card(oracle.valid_name(name.replace('+', ' ')))
        view = Card(c)
        return view.page()
    except InvalidDataException as e:
        raise DoesNotExistException(e)
Esempio n. 6
0
def card_tournament(name: str) -> str:
    try:
        c = cs.load_card(oracle.valid_name(urllib.parse.unquote_plus(name)),
                         season_id=get_season_id())
        view = Card(c, tournament_only=True)
        return view.page()
    except InvalidDataException as e:
        raise DoesNotExistException(e)
Esempio n. 7
0
def card(name: str, deck_type: Optional[str] = None) -> str:
    tournament_only = validate_deck_type(
        deck_type, [DeckType.ALL, DeckType.TOURNAMENT]) == DeckType.TOURNAMENT
    try:
        c = cs.load_card(oracle.valid_name(urllib.parse.unquote_plus(name)),
                         season_id=get_season_id())
        view = Card(c, tournament_only)
        return view.page()
    except InvalidDataException as e:
        raise DoesNotExistException(e)
Esempio n. 8
0
 async def background_task_spoiler_season(self) -> None:
     'Poll Scryfall for the latest 250 cards, and add them to our db if missing'
     try:
         await self.wait_until_ready()
         new_cards = await fetcher.scryfall_cards_async()
         for c in new_cards['data']:
             if c['layout'] == 'double_faced_token':
                 continue  # These cause issues for little benefit.  Let's just ignore them for now.
             try:
                 oracle.valid_name(c['name'])
                 await asyncio.sleep(1)
             except InvalidDataException:
                 multiverse.insert_card(c, True)
                 print('Imported {0} from Scryfall'.format(c['name']))
                 await asyncio.sleep(5)
             except TooFewItemsException:
                 pass
     except Exception:  # pylint: disable=broad-except
         await self.on_error('background_task_spoiler_season')
Esempio n. 9
0
def vivify(decklist: DecklistType) -> Deck:
    validated: DecklistType = {'maindeck': {}, 'sideboard': {}}
    invalid_names = set()
    for section in ['maindeck', 'sideboard']:
        for name, n in decklist.get(section, {}).items():
            try:
                validated[section][oracle.valid_name(name)] = n
            except InvalidDataException:
                invalid_names.add(name)
    if invalid_names:
        raise InvalidDataException('Invalid cards: {invalid_names}'.format(invalid_names='; '.join(invalid_names)))
    d = Deck({'maindeck': [], 'sideboard': []})
    for section in ['maindeck', 'sideboard']:
        for name, n in validated.get(section, {}).items():
            d[section].append(CardRef(name, n))
    return d
Esempio n. 10
0
def vivify(decklist):
    validated, invalid_names = {'maindeck': {}, 'sideboard': {}}, set()
    for section in ['maindeck', 'sideboard']:
        for name, n in decklist[section].items():
            try:
                validated[section][oracle.valid_name(name)] = n
            except InvalidDataException:
                invalid_names.add(name)
    if invalid_names:
        raise InvalidDataException('Invalid cards: {invalid_names}'.format(invalid_names='; '.join(invalid_names)))
    validated_names = list(validated['maindeck'].keys()) + list(validated['sideboard'].keys())
    cards = {c.name: c for c in oracle.load_cards(validated_names)}
    d = Deck({'maindeck': [], 'sideboard': []})
    for section in ['maindeck', 'sideboard']:
        for name, n in validated[section].items():
            d[section].append({'n': n, 'name': name, 'card': cards[name]})
    return d
Esempio n. 11
0
def insert_deck_card(deck_id: int, name: str, n: int, in_sideboard: bool) -> None:
    name = oracle.valid_name(name)
    sql = 'INSERT INTO deck_card (deck_id, card, n, sideboard) VALUES (%s, %s, %s, %s)'
    db().execute(sql, [deck_id, name, n, in_sideboard])
Esempio n. 12
0
def insert_deck_card(deck_id, name, n, in_sideboard):
    card = oracle.valid_name(name)
    sql = 'INSERT INTO deck_card (deck_id, card, n, sideboard) VALUES (%s, %s, %s, %s)'
    return db().execute(sql, [deck_id, card, n, in_sideboard])
Esempio n. 13
0
def test_valid_name() -> None:
    assert oracle.valid_name('Dark Ritual') == 'Dark Ritual'
    assert oracle.valid_name('Far/Away') == 'Far // Away'