from IPython import display
import pywikibot
from pywikibot import pagegenerators
import mwparserfromhell
import re

site = pywikibot.Site('commons', 'commons')
template = pywikibot.Page(site, 'Template:ImageNote')

transclusions = pagegenerators.ReferringPageGenerator(
    template, onlyTemplateInclusion=True)

regex = re.compile('{{ImageNote.*?}}\n(.*?)\n{{ImageNoteEnd.*?}}',
                   re.S )

for page in transclusions:
    text = page.text
    block = re.findall(regex, text)

    for match in block:
        wc = mwparserfromhell.parse(match)
        els = wc.filter_external_links()

        if els:
            display.display_markdown(
                f'[{page.title()}]({page.full_url()})', raw=True)
        for link in els:
            display.display_markdown(f'- {link.url}', raw=True)
Sleeping for 5.0 seconds, 2019-08-19 17:21:11
  • mailto:sayz@bil.omu.edu.tr