User:Ritchie333/wircsd.py

# # # import sys import re import pywikibot from pywikibot import pagegenerators reThreshold = re.compile( '^ @@(\d+)@@' ) rePattern = re.compile( '^ (-?\d+) /([^/]*)/' ) catName = u'Category:Candidates for speedy deletion' rulesName = 'Womeninred' if len( sys.argv ) > 1: rulesName = sys.argv[ 1 ] class AlexNewArtBotResult: threshold = 10 patterns = [] def __init__( self, rule ): page = pywikibot.Page( site, 'User:AlexNewArtBot/' + rule ) gotThreshold = False for line in page.text.splitlines: if not gotThreshold: match = reThreshold.match( line ) if not match is None: self.threshold = int( match.group( 1 ) ) gotThreshold = True else: match = rePattern.match( line ) if not match is None: value = int( match.group( 1 ) ) pattern = match.group( 2 ) self.patterns.append( ( value, pattern ) ) def score( self, title ): score = 0 page = pywikibot.Page( site, title ) for ( value, pattern ) in self.patterns: if re.search( pattern, page.text, re.IGNORECASE ) is not None: score = score + value return score site = pywikibot.Site rules = AlexNewArtBotResult( rulesName ) cat = pywikibot.Category( site, catName ) for page in pagegenerators.CategorizedPageGenerator( cat ): if 0 == page.namespace: title = page.title score = rules.score( title ) if score >= rules.threshold: print 'MATCH ' + title + ' = ' + str( score ) else: print title + ' = ' + str( score )
 * 1) !/usr/bin/python
 * 1) wircsd.py
 * 1) A pywikibot script to classify articles tagged for speedy deletion
 * 2) against a project, so that immediate attention can be applied.
 * 3) By default uses Womeninred
 * 4) Uses class AlexNewArtBotResult, which provides a Python wrapper to
 * 5)   the bot rules
 * 1) Usage : python pwb.py wircsd.py [Rules name]
 * 1) print 'test case'
 * 2) print rules.score( u'Annie Jump Cannon' )