User:Lupin/pywikipediabot
Appearance
Index: category.py =================================================================== RCS file: /cvsroot/pywikipediabot/pywikipedia/category.py,v retrieving revision 1.73 diff -u -w -r1.73 category.py --- category.py 28 Apr 2005 13:57:37 -0000 1.73 +++ category.py 9 May 2005 00:01:13 -0000 @@ -7,6 +7,7 @@ where action can be one of these: * add - mass-add a category to a list of pages + * dump - dump list of pages in a category * remove - remove category tag from all pages in a category * move - move all pages in a category to another category * tidy - tidy up a category by moving its articles into subcategories @@ -553,6 +554,21 @@ else: wikipedia.output(tree) +class CategoryDumpRobot: + def __init__(self, catTitle): + self.catTitle = catTitle + # get edit summary message + wikipedia.setAction(wikipedia.translate(wikipedia.getSite(),msg_change) % catTitle) + + def run(self): + cat = catlib.CatLink(wikipedia.getSite(), self.catTitle) + articles = cat.articles(recurse = 0) + if len(articles) == 0: + wikipedia.output(u'There are no articles in category ' + self.catTitle) + else: + for article in articles: + wikipedia.output(u'%s' % article) + if __name__ == "__main__": try: catDB = CategoryDatabase() @@ -572,6 +588,8 @@ action = 'tidy' elif arg == 'tree': action = 'tree' + elif arg == 'dump': + action = 'dump' elif arg == '-person': sort_by_last_name = True elif arg == '-rebuild': @@ -597,6 +615,10 @@ filename = wikipedia.input(u'Please enter the name of the file where the tree should be saved, or press enter to simply show the tree:') bot = CategoryTreeRobot(catTitle, catDB, filename) bot.run() + elif action == 'dump': + catTitle = wikipedia.input(u'Please enter the category you wish to dump:') + bot = CategoryDumpRobot(catTitle) + bot.run() else: # show help wikipedia.output(__doc__, 'utf-8')