예제 #1
0
def lex_card(c):
    """ Test the lexer against one card's text. """
    if isinstance(c, str):
        c = card.get_card(c)
    tokens = _token_stream(c.name, c.rules).getTokens()
    print(c.rules)
    pprint_tokens(tokens)
예제 #2
0
def lex_card(c):
    """ Test the lexer against one card's text. """
    if isinstance(c, str):
        c = card.get_card(c)
    tokens = _token_stream(c.name, c.rules).getTokens()
    print(c.rules)
    pprint_tokens(tokens)
예제 #3
0
def parse_card(c):
    """ Test the parser against a card. """
    Parser = DemystifyParser.DemystifyParser
    if isinstance(c, str):
        c = card.get_card(c)
    # mana cost
    ts = _token_stream(c.name, c.cost)
    ManaCostParser = Parser(ts)
    ManaCostParser.setCardState(c.name)
    parse_result = ManaCostParser.card_mana_cost()
    print(c.cost)
    pprint_tokens(ts.getTokens())
    print(parse_result.tree.toStringTree())
예제 #4
0
def parse_card(c):
    """ Test the parser against a card. """
    Parser = DemystifyParser.DemystifyParser
    if isinstance(c, str):
        c = card.get_card(c)
    # mana cost
    ts = _token_stream(c.name, c.cost)
    ManaCostParser = Parser(ts)
    ManaCostParser.setCardState(c.name)
    parse_result = ManaCostParser.card_mana_cost()
    print(c.cost)
    pprint_tokens(ts.getTokens())
    print(parse_result.tree.toStringTree())
예제 #5
0
def get_page_content(burl, terminal, selection):
    """ xxx """
    signals_content = get_card(selection, 1, burl, terminal)
    news_feed_content = get_feed(burl, terminal, selection)
    articles_content = ''+\
        get_list_articles(burl, 10, 'Latest analysis', 'article')+\
        get_list_articles(burl, 100, 'Intel, Reports, Analysis', 'perma')
    
    if terminal is None:
        signals_tab_active = 'active'
        signals_tab_fade = ''
        feed_tab_active = ''
        feed_tab_fade = 'fade'
    else:
        signals_tab_active = ''
        signals_tab_fade = 'fade'
        feed_tab_active = 'active'
        feed_tab_fade = ''
        
    tab_content = ''+\
    '<ul class="nav nav-tabs">'+\
    '<li class="nav-item"><a class="nav-link '+ signals_tab_active +'" data-toggle="pill" href="#signals">Signals</a></li>'+\
    '<li class="nav-item"><a  class="nav-link '+ feed_tab_active +'" data-toggle="pill" href="#feed">Feed</a></li>'+\
    '<li class="nav-item"><a  class="nav-link" data-toggle="pill" href="#analysis">Analysis</a></li>'+\
    '</ul>'+\
    ''+\
    '<div class="tab-content">'+\
    '<div id="signals" class="tab-pane '+\
    signals_tab_fade +' '+ signals_tab_active +'"'+\
    'style="padding-top: 15px">'+\
    signals_content +\
    '</div>'+\
    '<div id="feed" class="tab-pane '+ feed_tab_fade +' ' + feed_tab_active +'">'+\
    news_feed_content +\
    '</div>'+\
    '<div id="analysis" class="tab-pane fade">'+\
    articles_content+\
    '</div>'+\
    '</div>'
    
    return tab_content
예제 #6
0
def parse_helper(cards, name, rulename, yesregex=None, noregex=None):
    """ Parse a given subset of text on a given subset of cards.

        This function may override some re flags on the
        provided regex objects.

        cards: An iterable of cards to search for matching text. To save time,
            the provided regexes will be used to pare down this list to just
            those that will actually have text to attempt to parse.
        name: The function will be named _parse_{name} and the results for
            card c will be saved to c.parsed_{name}.
        rulename: The name of the parser rule to run.
        yesregex: If provided, run the parser rule on each match within each
            line of the card. The text selected is group 1 if it exists, or
            group 0 (the entire match) otherwise. If not provided, use each
            line in its entirety.
        noregex: Any text found after considering yesregex (or its absence)
            is skipped if it matches this regex. """
    def _parse_helper(c):
        """ Returns a pair (number of errors, set of unique errors). """
        results = []
        errors = 0
        uerrors = set()
        for lineno, line in enumerate(c.rules.split('\n')):
            lineno += 1
            if yesregex:
                texts = [
                    m.group(1) if m.groups() else m.group(0)
                    for m in yesregex.finditer(line)
                ]
            else:
                texts = [line]
            if noregex:
                texts = [text for text in texts if not noregex.match(text)]
            for text in texts:
                p, parse_result = _parse(rulename, text, c.name, lineno)
                tree = parse_result.tree
                results.append(tree)
                if p.getNumberOfSyntaxErrors():
                    mcase = _crawl_tree_for_errors(c.name, lineno, text, tree)
                    if mcase:
                        uerrors.add(mcase)
                    errors += 1
        return (c.name, [t.toStringTree() for t in results], errors, uerrors)

    _parse_helper.__name__ = '_parse_{}'.format(name)

    if yesregex:
        pattern = yesregex.pattern
        if noregex:
            ccards = {
                card.get_card(c[0])
                for c in card.search_text(pattern, cards=cards)
                if not noregex.match(c[1])
            }
        else:
            ccards = {
                card.get_card(c[0])
                for c in card.search_text(pattern, cards=cards)
            }
    elif noregex:
        ccards = {
            c
            for c in cards
            if not all(noregex.match(line) for line in c.rules.split('\n'))
        }
    else:
        ccards = set(cards)

    errors = 0
    uerrors = set()
    plog.removeHandler(_stdout)
    # list of (cardname, parsed result trees, number of errors, set of errors)
    results = card.map_multi(_parse_helper, ccards)
    cprop = 'parsed_{}'.format(name)
    for cname, pc, e, u in results:
        setattr(card.get_card(cname), cprop, pc)
        errors += e
        uerrors |= u
    plog.addHandler(_stdout)
    print('{} total errors.'.format(errors))
    if uerrors:
        print('{} unique cases missing.'.format(len(uerrors)))
        plog.debug('Missing cases: ' + '; '.join(sorted(uerrors)))
예제 #7
0
def parse_helper(cards, name, rulename, yesregex=None, noregex=None):
    """ Parse a given subset of text on a given subset of cards.

        This function may override some re flags on the
        provided regex objects.

        cards: An iterable of cards to search for matching text. To save time,
            the provided regexes will be used to pare down this list to just
            those that will actually have text to attempt to parse.
        name: The function will be named _parse_{name} and the results for
            card c will be saved to c.parsed_{name}.
        rulename: The name of the parser rule to run.
        yesregex: If provided, run the parser rule on each match within each
            line of the card. The text selected is group 1 if it exists, or
            group 0 (the entire match) otherwise. If not provided, use each
            line in its entirety.
        noregex: Any text found after considering yesregex (or its absence)
            is skipped if it matches this regex. """
    def _parse_helper(c):
        """ Returns a pair (number of errors, set of unique errors). """
        results = []
        errors = 0
        uerrors = set()
        for lineno, line in enumerate(c.rules.split('\n')):
            lineno += 1
            if yesregex:
                texts = [m.group(1) if m.groups() else m.group(0)
                         for m in yesregex.finditer(line)]
            else:
                texts = [line]
            if noregex:
                texts = [text for text in texts if not noregex.match(text)]
            for text in texts:
                p, parse_result = _parse(rulename, text, c.name, lineno)
                tree = parse_result.tree
                results.append(tree)
                if p.getNumberOfSyntaxErrors():
                    mcase = _crawl_tree_for_errors(c.name, lineno, text, tree)
                    if mcase:
                        uerrors.add(mcase)
                    errors += 1
        return (c.name, [t.toStringTree() for t in results], errors, uerrors)
    _parse_helper.__name__ = '_parse_{}'.format(name)

    if yesregex:
        pattern = yesregex.pattern
        if noregex:
            ccards = {card.get_card(c[0])
                      for c in card.search_text(pattern, cards=cards)
                      if not noregex.match(c[1])}
        else:
            ccards = {card.get_card(c[0])
                      for c in card.search_text(pattern, cards=cards)}
    elif noregex:
        ccards = {c for c in cards
                  if not all(noregex.match(line)
                             for line in c.rules.split('\n'))}
    else:
        ccards = set(cards)

    errors = 0
    uerrors = set()
    plog.removeHandler(_stdout)
    # list of (cardname, parsed result trees, number of errors, set of errors)
    results = card.map_multi(_parse_helper, ccards)
    cprop = 'parsed_{}'.format(name)
    for cname, pc, e, u in results:
        setattr(card.get_card(cname), cprop, pc)
        errors += e
        uerrors |= u
    plog.addHandler(_stdout)
    print('{} total errors.'.format(errors))
    if uerrors:
        print('{} unique cases missing.'.format(len(uerrors)))
        plog.debug('Missing cases: ' + '; '.join(sorted(uerrors)))
예제 #8
0
# loop for finding set and clicking on it
for i in range(
        len(
            browser.find_elements_by_xpath(
                "//div[@id='expansionList']/div/ul/li/a"))):
    if i < 60:
        continue
    browser.find_elements_by_xpath(
        "//div[@id='expansionList']/div/ul/li/a")[i].click()
    time.sleep(pause)
    browser.find_elements_by_xpath(
        '//a[contains(@href, "?cardno=")]')[0].click()
    time.sleep(pause)

    get_card(browser=browser)

    disabled = True
    while disabled:
        try:
            browser.find_element_by_xpath(
                '//p[@class="neighbor"]/span[@class="disable" and contains(text(), "next")]'
            )
        except NoSuchElementException:
            browser.find_element_by_xpath(
                "//p[@class='neighbor']/a[contains(text(), 'next')]").click()
            time.sleep(pause)

            get_card(browser=browser)

            continue