コード例 #1
0
    def handleMatch(self, m):
        name = m.group(3)
        if name:
            name = name.strip()
        set = m.group(5)
        if set:
            set = set.strip()
        link_text = m.group(7)

        card = parsers.card_from(name, set)

        if card is None:  # Not a valid card, return the raw input
            return u''.join(m.groups('')[1:])

        src = BASE_CARD_URL.format(card.multiverse_id)
        alt = u"{} ({})".format(card.name.name, card.set.set)
        content = TEMPLATE.format(src, alt)

        el = markdown.util.etree.Element('a')
        el.set('class', 'card-tooltip')
        el.set('rel', 'tooltip')
        el.set('data-title', content)
        if not link_text:
            link_text = card.name.name
        el.text = link_text
        return el
コード例 #2
0
def load_synergy(session, hash, title, description, *cards):
    has_model = lambda model, **kw: _has_model(session, model, **kw)
    if has_model(Synergy, hash=hash):
        log.info("Skipping help file synergy creation for hash {}: hash already defined.".format(hash))
        return
    synergy = Synergy(hash=hash, create_date=datetime.now(), title=title, description=description, view_count=0, visible=True)
    for i, card in enumerate(cards):
        text_match = text_regex.search(card)
        card_match = card_regex.search(card)
        if text_match:
            count = text_match.group('count')
            if count:
                count = count.strip()
            count = int(count) if count else 1

            text = text_match.group('text')
            if text:
                text = text.strip()

            synergy_text = SynergyText(synergy=synergy, text=text, index=i, quantity=count)
            session.add(synergy_text)
        elif card_match:
            count = card_match.group('count')
            if count:
                count = count.strip()
            count = int(count) if count else 1

            card = card_match.group('card')
            if card:
                card = card.strip()

            set = card_match.group('set')
            if set:
                set = set.strip()

            card = parsers.card_from(card, set)

            synergy_card = SynergyCard(synergy=synergy, card=card, index=i, quantity=count)
            session.add(synergy_card)
    log.info("Generated help file synergy for hash {}".format(hash))
コード例 #3
0
ファイル: synergy.py プロジェクト: numberoverzero/mtg-query
    def from_string(cls, string):
        '''Does not set up index or synergy_id'''
        string = string.strip()
        match = CARD_REGEX.search(string)
        if not match:
            raise InvalidDataException("Incorrect card format")

        count = match.group('count')
        if count:
            count = count.strip()
        count = int(count) if count else 1

        name = match.group('name')
        if name:
            name = name.strip()

        set = match.group('set')
        if set:
            set = set.strip()

        card = parsers.card_from(name, set)
        return cls(card=card, quantity=count)