def get_simple_text(wtext, key, clean=True):

    text = None

    keys = key if type(key) is list else [key]

    template_dict = adapter.template_dict(wtext)
    wtext_lines = wtext_help.get_wtext_lines(wtext)

    if keys:
        for possible_key in keys:

            # try getting from parserfromhell
            if not text and template_dict:
                text = template_dict.get(possible_key)

            # final attempt if still no text
            if not text and wtext_lines:
                matched_line = wtext_help.find_key_val_line(wtext, possible_key)
                if matched_line:
                    key_val = matched_line.strip(' \t\n\r').split("=", 1)
                    if len(key_val) == 2:
                        text = key_val[1].strip()

    if text and clean:
        text = clean_help.clean_text(text)

    return text
Example #2
0
def page_name(wtext):

    name = parse.get_simple_text(wtext, ['name', 'show_name', 'season_name', 'film name'])

    if not name:
        name = extract_page_name(wtext)

    return clean_help.clean_text(name)