Jump to content

User:Ritchie333/afcbios.py

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
#!/usr/bin/python

import sys
import re
import pywikibot
from pywikibot import pagegenerators

name = 'Category:AfC submissions declined as a non-notable biography'
reText = re.compile( '(She is|She was|Her work|Her book)' )
reMarker = re.compile( '<ref.*\/ref>|{{.*}}|<!--.*-->|\'\'\'|----' )
reTitle = re.compile( '\(.*\)' )

site = pywikibot.Site()
cat = pywikibot.Category(site,name)
gen = pagegenerators.CategorizedPageGenerator(cat)
count = 0
for page in gen:
  ns = page.namespace()
  if( 118 == ns):
    text = page.text
    match = reText.search( text )
    if( match is not None ):
      if 0 == ( count % 50 ):
        print '== ' + str( count + 1 ) + ' - ' + str( count + 50 ) + ' =='
      title = page.title( False, False )
      print '* [[Draft:' + title.encode( 'utf-8' ) + ']]'
      shortText = reMarker.sub( '', text )
      shortTitle = reTitle.sub( '', title )
      sentences = re.search( shortTitle + '.*\.', shortText )
      if not sentences is None:
        components = sentences.group().partition( '.' )
        lead = components[ 0 ].replace( '<ref', 'ref' )
        print '::<small>' + lead.encode( 'utf-8' ) + '.</small>'
      count += 1