Revision: 6149 Author: purodha Date: 2008-12-15 13:28:38 +0000 (Mon, 15 Dec 2008)
Log Message: ----------- Add -hintnobracket parameter to interwiki.py solving bug 1729378, https://sourceforge.net/support/tracker.php?aid=1729378
Modified Paths: -------------- trunk/pywikipedia/interwiki.py trunk/pywikipedia/titletranslate.py
Modified: trunk/pywikipedia/interwiki.py =================================================================== --- trunk/pywikipedia/interwiki.py 2008-12-14 11:38:53 UTC (rev 6148) +++ trunk/pywikipedia/interwiki.py 2008-12-15 13:28:38 UTC (rev 6149) @@ -77,7 +77,8 @@ where to start looking for translations. This is only useful if you specify a single page to work on. If no text is given after the second ':', the name of the page - itself is used as the title for the hint. + itself is used as the title for the hint, unless the + -hintnobracket command line option (see there) is also selected.
There are some special hints, trying a number of languages at once: @@ -123,6 +124,12 @@ dates, only use found links and hints. (note: without ending colon)
+ -hintnobracket used to make the robot strip everything in brackets, + and surrounding spaces from the page name, before it is + used in a -hint:xy: where the page name has been left out, + or -hint:all:, -hint:10:, etc. without a name, or + an -askhint reply, where only a language is given. + These arguments define how much user confirmation is required:
-autonomous run automatically, do not ask any questions. If a question @@ -456,6 +463,7 @@ untranslatedonly = False askhints = False auto = True + hintnobracket = False neverlink = [] showtextlink = 0 showtextlinkadd = 300 @@ -546,11 +554,14 @@ """Add the given translation hints to the todo list""" if globalvar.same: if hints: - pages = titletranslate.translate(self.originPage, hints = hints + ['all:'], auto = globalvar.auto) + pages = titletranslate.translate(self.originPage, hints = hints + ['all:'], auto = globalvar.auto, removebrackets += globalvar.hintnobracket) else: - pages = titletranslate.translate(self.originPage, hints = ['all:'], auto = globalvar.auto) + pages = titletranslate.translate(self.originPage, hints = ['all:'], auto = globalvar.auto, removebrackets += globalvar.hintnobracket) else: - pages = titletranslate.translate(self.originPage, hints = hints, auto = globalvar.auto) + pages = titletranslate.translate(self.originPage, hints = hints, auto = globalvar.auto, removebrackets += globalvar.hintnobracket) for page in pages: self.todo.append(page) self.foundIn[page] = [None] @@ -758,7 +769,8 @@ elif not newhint: break else: - pages = titletranslate.translate(self.originPage, hints = [newhint], auto = globalvar.auto) + pages = titletranslate.translate(self.originPage, hints = [newhint], auto = globalvar.auto, removebrackets += globalvar.hintnobracket) for page in pages: self.addIfNew(page, counter, None)
@@ -1617,6 +1629,8 @@ globalvar.askhints = True elif arg == '-noauto': pass + elif arg == '-hintnobracket': + globalvar.hintnobracket = True elif arg.startswith('-warnfile:'): warnfile = arg[10:] elif arg == '-confirm':
Modified: trunk/pywikipedia/titletranslate.py =================================================================== --- trunk/pywikipedia/titletranslate.py 2008-12-14 11:38:53 UTC (rev 6148) +++ trunk/pywikipedia/titletranslate.py 2008-12-15 13:28:38 UTC (rev 6149) @@ -11,7 +11,7 @@
import wikipedia, date, time
-def translate(page, hints = None, auto = True): +def translate(page, hints = None, auto = True, removebrackets = False): """ Please comment your source code! --Daniel
@@ -30,13 +30,16 @@ if newname == '': # if given as -hint:xy or -hint:xy:, assume that there should # be a page in language xy with the same title as the page - # we're currently working on + # we're currently working on ... ns = page.namespace() if ns: newname = u'%s:%s' % (site.family.namespace('_default', ns), page.titleWithoutNamespace()) else: # article in the main namespace newname = page.title() + # ... unless we do want brackets + if removebrackets: + newname = re.sub(re.compile(ur"\W*?(.*?)\W*?", re.UNICODE), u" ", newname) try: number = int(codes) codes = site.family.languages_by_size[:number]