Jump to content

User:Ritchie333/dyks.py

From Wikipedia, the free encyclopedia
# A pywikibot script to dump out all DYK nominations in a list
import re
import pywikibot
from pywikibot import pagegenerators
import sys

username = sys.argv[ 1 ]

reDYK = re.compile( '^Giving DYK credit for \[\[([^\]]+)\]\]' )

site = pywikibot.Site()
tp = pywikibot.Page( site, 'User talk:' + username )
for rev in tp.revisions(reverse=True):
    if rev.user == 'DYKUpdateBot':
        match = reDYK.match( rev.comment )
        if match is not None:
            page = match.group( 1 )
            print( '# ' + rev.timestamp.strftime( '%d %B %Y' ) + ' [[' + page + ']]' )