http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9297
Revision: 9297
Author: xqt
Date: 2011-06-14 10:27:11 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
+svn properties eol-style,keywords
Modified Paths:
--------------
trunk/pywikipedia/create_categories.py
Property Changed:
----------------
trunk/pywikipedia/create_categories.py
Modified: trunk/pywikipedia/create_categories.py
===================================================================
--- trunk/pywikipedia/create_categories.py 2011-06-13 16:50:59 UTC (rev 9296)
+++ trunk/pywikipedia/create_categories.py 2011-06-14 10:27:11 UTC (rev 9297)
@@ -1,100 +1,100 @@
-# -*- coding: utf-8 -*-
-"""
-Program to batch create categories.
-
-The program expects a generator containing a list of page titles to be used as base.
-
-The following command line parameters are supported:
-
--alway (not implemented yet) Don't ask, just do the edit.
-
--overwrite (not implemented yet).
-
--parent The name of the parent category.
-
--basename The base to be used for the new category names.
-
-Example:
-create_categories.py
- -lang:commons
- -family:commons
- -links:User:Multichill/Wallonia
- -parent:"Cultural heritage monuments in Wallonia"
- -basename:"Cultural heritage monuments in"
-
-"""
-__version__ = '$Id: create_categories.py 9042 2011-03-13 10:14:47Z xqt $'
-#
-# (C) Multichill 2011
-#
-# Distributed under the terms of the MIT license.
-#
-#
-import os, sys, re, codecs
-import urllib, httplib, urllib2
-import catlib
-import time
-import socket
-import StringIO
-import wikipedia as pywikibot
-import config
-import pagegenerators
-
-
-def createCategory(page, parent, basename):
- title = page.titleWithoutNamespace()
-
- newpage = pywikibot.Page(pywikibot.getSite(u'commons', u'commons'),
- u'Category:' + basename + u' ' + title)
- newtext = u''
- newtext += u'[[Category:' + parent + u'|' + title + u']]\n'
- newtext += u'[[Category:' + title + u']]\n'
-
- if not newpage.exists():
- #FIXME: Add user prompting and -always option
- pywikibot.output(newpage.title())
- pywikibot.showDiff(u'', newtext)
-
- comment = u'Creating new category'
- #FIXME: Add exception handling
- newpage.put(newtext, comment)
- else:
- #FIXME: Add overwrite option
- pywikibot.output(u'%s already exists, skipping' % (newpage.title(),))
-
-
-def main(args):
- '''
- Main loop. Get a generator and options.
- '''
- generator = None
- parent = u''
- basename = u''
- always = False
-
- genFactory = pagegenerators.GeneratorFactory()
-
- for arg in pywikibot.handleArgs():
- if arg == '-always':
- always = True
- elif arg.startswith('-parent:'):
- parent = arg [len('-parent:'):].strip()
- elif arg.startswith('-basename'):
- basename = arg [len('-basename:'):].strip()
- else:
- genFactory.handleArg(arg)
-
- generator = genFactory.getCombinedGenerator()
- if generator:
- for page in generator:
- createCategory(page, parent, basename)
- else:
- pywikibot.output(u'No pages to work on')
-
- pywikibot.output(u'All done')
-
-if __name__ == "__main__":
- try:
- main(sys.argv[1:])
- finally:
- pywikibot.stopme()
+# -*- coding: utf-8 -*-
+"""
+Program to batch create categories.
+
+The program expects a generator containing a list of page titles to be used as base.
+
+The following command line parameters are supported:
+
+-alway (not implemented yet) Don't ask, just do the edit.
+
+-overwrite (not implemented yet).
+
+-parent The name of the parent category.
+
+-basename The base to be used for the new category names.
+
+Example:
+create_categories.py
+ -lang:commons
+ -family:commons
+ -links:User:Multichill/Wallonia
+ -parent:"Cultural heritage monuments in Wallonia"
+ -basename:"Cultural heritage monuments in"
+
+"""
+__version__ = '$Id$'
+#
+# (C) Multichill 2011
+#
+# Distributed under the terms of the MIT license.
+#
+#
+import os, sys, re, codecs
+import urllib, httplib, urllib2
+import catlib
+import time
+import socket
+import StringIO
+import wikipedia as pywikibot
+import config
+import pagegenerators
+
+
+def createCategory(page, parent, basename):
+ title = page.titleWithoutNamespace()
+
+ newpage = pywikibot.Page(pywikibot.getSite(u'commons', u'commons'),
+ u'Category:' + basename + u' ' + title)
+ newtext = u''
+ newtext += u'[[Category:' + parent + u'|' + title + u']]\n'
+ newtext += u'[[Category:' + title + u']]\n'
+
+ if not newpage.exists():
+ #FIXME: Add user prompting and -always option
+ pywikibot.output(newpage.title())
+ pywikibot.showDiff(u'', newtext)
+
+ comment = u'Creating new category'
+ #FIXME: Add exception handling
+ newpage.put(newtext, comment)
+ else:
+ #FIXME: Add overwrite option
+ pywikibot.output(u'%s already exists, skipping' % (newpage.title(),))
+
+
+def main(args):
+ '''
+ Main loop. Get a generator and options.
+ '''
+ generator = None
+ parent = u''
+ basename = u''
+ always = False
+
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in pywikibot.handleArgs():
+ if arg == '-always':
+ always = True
+ elif arg.startswith('-parent:'):
+ parent = arg [len('-parent:'):].strip()
+ elif arg.startswith('-basename'):
+ basename = arg [len('-basename:'):].strip()
+ else:
+ genFactory.handleArg(arg)
+
+ generator = genFactory.getCombinedGenerator()
+ if generator:
+ for page in generator:
+ createCategory(page, parent, basename)
+ else:
+ pywikibot.output(u'No pages to work on')
+
+ pywikibot.output(u'All done')
+
+if __name__ == "__main__":
+ try:
+ main(sys.argv[1:])
+ finally:
+ pywikibot.stopme()
Property changes on: trunk/pywikipedia/create_categories.py
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native