Revision: 8545 Author: xqt Date: 2010-09-13 04:53:26 +0000 (Mon, 13 Sep 2010)
Log Message: ----------- update from trunk
Modified Paths: -------------- branches/rewrite/scripts/titletranslate.py
Modified: branches/rewrite/scripts/titletranslate.py =================================================================== --- branches/rewrite/scripts/titletranslate.py 2010-09-13 04:52:47 UTC (rev 8544) +++ branches/rewrite/scripts/titletranslate.py 2010-09-13 04:53:26 UTC (rev 8545) @@ -2,6 +2,7 @@ # # (C) Rob W.W. Hooft, 2003 # (C) Yuri Astrakhan, 2005 +# (C) Pywikipedia bot team, 2003-2010 # # Distributed under the terms of the MIT license. # @@ -9,7 +10,7 @@ # import re
-import pywikibot, time +import pywikibot import pywikibot.date as date
def translate(page, hints = None, auto = True, removebrackets = False): @@ -22,7 +23,7 @@ site = page.site if hints: for h in hints: - if h.find(':') == -1: + if ':' not in h: # argument given as -hint:xy where xy is a language code codes = h newname = '' @@ -34,7 +35,8 @@ # we're currently working on ... ns = page.namespace() if ns: - newname = u'%s:%s' % (site.family.namespace('_default', ns), page.title(withNamespace=False)) + newname = u'%s:%s' % (site.family.namespace('_default', ns), + page.title(withNamespace=False)) else: # article in the main namespace newname = page.title() @@ -59,24 +61,41 @@ result.append(x) else: if pywikibot.verbose: - pywikibot.output(u"Ignoring unknown language code %s"%newcode) + pywikibot.output(u"Ignoring unknown language code %s" + % newcode)
- # Autotranslate dates into all other languages, the rest will come from existing interwiki links. + # Autotranslate dates into all other languages, the rest will come from + # existing interwiki links. if auto: # search inside all dictionaries for this link - dictName, value = date.getAutoFormat( page.site.code, page.title() ) + dictName, value = date.getAutoFormat(page.site.code, + page.title()) if dictName: - if not (dictName == 'yearsBC' and date.maxyearBC.has_key(page.site.code) and value > date.maxyearBC[page.site.code]) or (dictName == 'yearsAD' and date.maxyearAD.has_key(page.site.code) and value > date.maxyearAD[page.site.code]): - pywikibot.output(u'TitleTranslate: %s was recognized as %s with value %d' % (page.title(),dictName,value)) + if not (dictName == 'yearsBC' and + page.site.code in date.maxyearBC and + value > date.maxyearBC[page.site.code]) or \ + (dictName == 'yearsAD' and + page.site.code in date.maxyearAD and + value > date.maxyearAD[page.site.code]): + pywikibot.output( + u'TitleTranslate: %s was recognized as %s with value %d' + % (page.title(), dictName, value)) for entryLang, entry in date.formats[dictName].iteritems(): if entryLang != page.site.code: - if dictName == 'yearsBC' and date.maxyearBC.has_key(entryLang) and value > date.maxyearBC[entryLang]: + if dictName == 'yearsBC' and \ + entryLang in date.maxyearBC and \ + value > date.maxyearBC[entryLang]: pass - elif dictName == 'yearsAD' and date.maxyearAD.has_key(entryLang) and value > date.maxyearAD[entryLang]: + elif dictName == 'yearsAD' and \ + entryLang in date.maxyearAD and \ + value > date.maxyearAD[entryLang]: pass else: newname = entry(value) - x = pywikibot.Link( newname, pywikibot.getSite(code=entryLang, fam=site.family) ) + x = pywikibot.Link( + newname, + pywikibot.getSite(code=entryLang, + fam=site.family)) if x not in result: result.append(x) # add new page return result @@ -89,36 +108,28 @@
def getPoisonedLinks(pl): """Returns a list of known corrupted links that should be removed if seen + """ result = [] - - pywikibot.output( u'getting poisoned links for %s' % pl.title() ) - - dictName, value = date.getAutoFormat( pl.site.code, pl.title() ) + pywikibot.output(u'getting poisoned links for %s' % pl.title()) + dictName, value = date.getAutoFormat(pl.site.code, pl.title()) if dictName is not None: pywikibot.output( u'date found in %s' % dictName ) - # errors in year BC if dictName in date.bcFormats: for fmt in bcDateErrors: result.append( fmt % value ) - # i guess this is like friday the 13th for the years if value == 398 and dictName == 'yearsBC': - appendFormatedDates( result, dictName, 399 ) - + appendFormatedDates(result, dictName, 399) if dictName == 'yearsBC': - appendFormatedDates( result, 'decadesBC', value ) - appendFormatedDates( result, 'yearsAD', value ) - + appendFormatedDates(result, 'decadesBC', value) + appendFormatedDates(result, 'yearsAD', value) if dictName == 'yearsAD': - appendFormatedDates( result, 'decadesAD', value ) - appendFormatedDates( result, 'yearsBC', value ) - + appendFormatedDates(result, 'decadesAD', value) + appendFormatedDates(result, 'yearsBC', value) if dictName == 'centuriesBC': - appendFormatedDates( result, 'decadesBC', value*100+1 ) - + appendFormatedDates(result, 'decadesBC', value * 100 + 1) if dictName == 'centuriesAD': - appendFormatedDates( result, 'decadesAD', value*100+1 ) - + appendFormatedDates(result, 'decadesAD', value * 100 + 1) return result