<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import sys <EOL> import pywikibot <EOL> import catlib <EOL> import pagegenerators <EOL> def filterCategory ( page ) : <EOL> """<STR_LIT>""" <EOL> site = page . site ( ) <EOL> title = page . title ( ) <EOL> category = catlib . Category ( site , title ) <EOL> for subcat in category . subcategories ( ) : <EOL> filterSubCategory ( subcat , category ) <EOL> def filterSubCategory ( subcat , category ) : <EOL> """<STR_LIT>""" <EOL> articleGen = pagegenerators . PreloadingGenerator ( <EOL> pagegenerators . CategorizedPageGenerator ( subcat ) ) <EOL> for article in articleGen : <EOL> pywikibot . output ( u'<STR_LIT>' % ( article . title ( ) , ) ) <EOL> articleCategories = article . categories ( ) <EOL> if category in articleCategories : <EOL> articleCategories . remove ( category ) <EOL> text = article . get ( ) <EOL> newtext = pywikibot . replaceCategoryLinks ( text , articleCategories ) <EOL> pywikibot . showDiff ( text , newtext ) <EOL> comment = ( u'<STR_LIT>' <EOL> % ( category . title ( ) , subcat . title ( ) ) ) <EOL> article . put ( newtext , comment ) <EOL> def main ( args ) : <EOL> generator = None <EOL> genFactory = pagegenerators . GeneratorFactory ( ) <EOL> for arg in pywikibot . handleArgs ( ) : <EOL> genFactory . handleArg ( arg ) <EOL> generator = genFactory . getCombinedGenerator ( ) <EOL> if not generator : <EOL> return False <EOL> for page in generator : <EOL> if page . exists ( ) and page . namespace ( ) == <NUM_LIT> : <EOL> filterCategory ( page ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> main ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> finally : <EOL> print "<STR_LIT>" </s>
