Exemple #1
0
def from_citeweb(wikicode: Wikicode) -> Wikicode:
    count = 0
    for t in wikicode.filter_templates():
        if t.name == 'Cite web' and not t.has(format) and not t.has('author'):
            title = getvalue(t, 'title')
            url = getvalue(t, 'url')
            date = format_date(getvalue(t, 'date'))
            website = getvalue(t, 'website')
            publisher = getvalue(t, 'publisher')
            accessdate = format_date(getvalue(t, 'accessdate')) if getvalue(
                t, 'accessdate') else format_date(getvalue(t, 'access-date'))

            if all(title, url, accessdate):
                new = f'“[{url} {title}]”'

                if publisher and website:
                    new += f'. \'\'{website}\'\'. {publisher} ({date}). ' if date else f'. \'\'{website}\'\'. {publisher}. '
                elif publisher and not website:
                    new += f'. {publisher} ({date}). ' if date else f'. {publisher}. '
                elif not publisher and website:
                    new += f'. \'\'{website}\'\' ({date}). ' if date else f'. \'\'{website}\'\'. '
                else:
                    new += f' ({date}) .' if date else f'. '
                new += f'{accessdate}閲覧。'

                wikicode.replace(t, new)
                count += 1

    pywikibot.output(f'{{{{Cite web}}}} を {count} 回置換しました')
    return wikicode
Exemple #2
0
def get_ety(wikicode: Wikicode):
    if " + " in wikicode:
        yield "exception", mk_unknown_structure("mwe-ety")
    templates = wikicode.filter_templates()
    t_match = template_matchers(templates)
    deriv_templates = t_match.intersection(ALL_DERIV_TEMPLATES)
    if len(deriv_templates) > 1:
        yield "exception", mk_unknown_structure("multi-template-ety")
    elif len(deriv_templates) == 1:
        yield from proc_ety_derivation_template(
            templates[t_match.index(deriv_templates[0])]
        )
    else:
        pass
    other_templates = t_match.difference(ALL_DERIV_TEMPLATES)
    for t_match in other_templates:
        yield "exception", mk_unknown_structure("unknown-template-ety", list(t_match))
Exemple #3
0
def block_templates(contents: Wikicode) -> List[Template]:
    return [
        t for t in contents.filter_templates()
        if t.name not in INLINE_TEMPLATES
    ]