http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11694
Revision: 11694
Author: xqt
Date: 2013-06-24 17:04:14 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
strip trailing whitespace, PEP8 changes from trunk
Modified Paths:
--------------
branches/rewrite/scripts/harvest_template.py
Modified: branches/rewrite/scripts/harvest_template.py
===================================================================
--- branches/rewrite/scripts/harvest_template.py 2013-06-24 16:57:24 UTC (rev 11693)
+++ branches/rewrite/scripts/harvest_template.py 2013-06-24 17:04:14 UTC (rev 11694)
@@ -1,27 +1,33 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-Copyright (C) 2013 Multichill
-Copyright (C) 2013 Pywikipediabot team
-
-Distributed under the MIT License
-
Usage:
python harvest_template.py -lang:nl -template:"Taxobox straalvinnige" orde P70 familie P71 geslacht P74
-This will work on all pages that transclude the template in the article namespace
+This will work on all pages that transclude the template in the article
+namespace
-You can use any typical pagegenerator to provide with a list of pages
+You can use any typical pagegenerator to provide with a list of pages:
python harvest_template.py -lang:nl -cat:Sisoridae -template:"Taxobox straalvinnige" -namespace:0 orde P70 familie P71 geslacht P74
"""
+#
+# (C) 2013 Multichill, Amir
+# (C) 2013 Pywikipediabot team
+#
+# Distributed under the terms of MIT License.
+#
+__version__ = '$Id: harvest_template.py 11692 2013-06-24 16:55:46Z xqt $'
+#
+
import re
import json
import pywikibot
-from pywikibot import pagegenerators
+from pywikibot import pagegenerators as pg
+
class HarvestRobot:
"""
A bot to add Wikidata claims
@@ -77,15 +83,18 @@
templates = pywikibot.extract_templates_and_params(pagetext)
for (template, fielddict) in templates:
# We found the template we were looking for
- if template.replace(u'_', u' ')==self.templateTitle:
+ if template.replace(u'_', u' ') == self.templateTitle:
for field, value in fielddict.items():
# This field contains something useful for us
if field in self.fields:
# Check if the property isn't already set
claim = pywikibot.Claim(self.repo, self.fields[field])
if claim.getID() in item.get().get('claims'):
- pywikibot.output(u'A claim for %s already exists. Skipping' % (claim.getID(),))
- #TODO FIXME: This is a very crude way of dupe checking
+ pywikibot.output(
+ u'A claim for %s already exists. Skipping'
+ % claim.getID())
+ # TODO FIXME: This is a very crude way of dupe
+ # checking
else:
if claim.getType() == 'wikibase-item':
# Try to extract a valid page
@@ -114,7 +123,7 @@
def main():
- gen = pagegenerators.GeneratorFactory()
+ gen = pg.GeneratorFactory()
commandline_arguments = list()
templateTitle = u''
for arg in pywikibot.handleArgs():
@@ -133,8 +142,8 @@
raise ValueError # or something.
fields = dict()
- for i in xrange (0, len(commandline_arguments), 2):
- fields[commandline_arguments[i]] = commandline_arguments[i+1]
+ for i in xrange(0, len(commandline_arguments), 2):
+ fields[commandline_arguments[i]] = commandline_arguments[i + 1]
generator = gen.getCombinedGenerator()
if not generator:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11692
Revision: 11692
Author: xqt
Date: 2013-06-24 16:55:46 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
strip trailing whitespace, PEP8 changes
Modified Paths:
--------------
trunk/pywikipedia/harvest_template.py
Property Changed:
----------------
trunk/pywikipedia/harvest_template.py
Modified: trunk/pywikipedia/harvest_template.py
===================================================================
--- trunk/pywikipedia/harvest_template.py 2013-06-24 13:54:35 UTC (rev 11691)
+++ trunk/pywikipedia/harvest_template.py 2013-06-24 16:55:46 UTC (rev 11692)
@@ -3,11 +3,12 @@
"""
Usage:
-python harvest_template.py -lang:nl -template:"Taxobox straalvinnige" orde P70 familie P71 geslacht P74
+python harvest_template.py -lang:nl -template:"Taxobox straalvinnige" orde P70 familie P71 geslacht P74
-This will work on all pages that transclude the template in the article namespace
+This will work on all pages that transclude the template in the article
+namespace
-You can use any typical pagegenerator to provide with a list of pages
+You can use any typical pagegenerator to provide with a list of pages:
python harvest_template.py -lang:nl -cat:Sisoridae -template:"Taxobox straalvinnige" -namespace:0 orde P70 familie P71 geslacht P74
@@ -23,8 +24,9 @@
import re
import wikipedia as pywikibot
-import pagegenerators
+import pagegenerators as pg
+
class HarvestRobot:
"""
A bot to add Wikidata claims
@@ -39,11 +41,11 @@
"""
self.generator = generator
self.templateTitle = templateTitle.replace(u'_', u' ')
- self.pregen=pagegenerators.PreloadingGenerator(generator)
+ self.pregen = pg.PreloadingGenerator(generator)
self.fields = fields
- self.site=pywikibot.getSite()
+ self.site = pywikibot.getSite()
self.repo = self.site.data_repository()
-
+
def setSource(self, lang):
'''
Get the source
@@ -66,10 +68,10 @@
'be': 'Q877583',
'uk': 'Q199698',
'tr': 'Q58255',
- } # TODO: Should be moved to a central wikidata library
-
+ } # TODO: Should be moved to a central wikidata library
+
if lang in source_values:
- source = ('143',source_values.get(lang))
+ source = ('143', source_values.get(lang))
return source
else:
return None
@@ -96,36 +98,51 @@
templates = pywikibot.extract_templates_and_params(pagetext)
for (template, fielddict) in templates:
# We found the template we were looking for
- if template.replace(u'_', u' ')==self.templateTitle:
+ if template.replace(u'_', u' ') == self.templateTitle:
for field, value in fielddict.items():
# This field contains something useful for us
if field in self.fields:
# Check if the property isn't already set
- claim = self.fields[field]
+ claim = self.fields[field]
if claim in item.get().get('claims'):
- pywikibot.output(u'A claim for %s already exists. Skipping' % (claim,))
- #TODO FIXME: This is a very crude way of dupe checking
+ pywikibot.output(
+ u'A claim for %s already exists. Skipping'
+ % (claim,))
+ # TODO FIXME: This is a very crude way of dupe
+ # checking
else:
# Try to extract a valid page
- match = re.search(re.compile(r'\[\[(?P<title>[^\]|[#<>{}]*)(\|.*?)?\]\]'), value)
+ match = re.search(re.compile(
+ r'\[\[(?P<title>[^\]|[#<>{}]*)(\|.*?)?\]\]'),
+ value)
if match:
try:
link = match.group(1)
- linkedPage = pywikibot.Page(self.site, link)
+ linkedPage = pywikibot.Page(self.site,
+ link)
if linkedPage.isRedirectPage():
linkedPage = linkedPage.getRedirectTarget()
linkedItem = pywikibot.DataPage(linkedPage)
- pywikibot.output('Adding %s --> %s' % (claim, linkedItem.getID()))
+ pywikibot.output('Adding %s --> %s'
+ % (claim,
+ linkedItem.getID()))
if self.setSource(self.site().language()):
- item.editclaim(str(claim), linkedItem.getID() ,refs={self.setSource(self.site().language())})
+ item.editclaim(
+ str(claim),
+ linkedItem.getID(),
+ refs={self.setSource(
+ self.site().language())})
else:
- item.editclaim(str(claim), linkedItem.getID() )
+ item.editclaim(str(claim),
+ linkedItem.getID())
except pywikibot.NoPage:
- pywikibot.output('[[%s]] doesn\'t exist so I can\'t link to it' % (linkedItem.title(),))
-
+ pywikibot.output(
+ "[[%s]] doesn't exist so I can't link to it"
+ % linkedItem.title())
+
def main():
- genFactory = pagegenerators.GeneratorFactory()
+ genFactory = pg.GeneratorFactory()
commandline_arguments = list()
templateTitle = u''
for arg in pywikibot.handleArgs():
@@ -139,21 +156,24 @@
continue
else:
commandline_arguments.append(arg)
-
+
if len(commandline_arguments) % 2 or not templateTitle:
raise ValueError # or something.
fields = dict()
- for i in xrange (0, len(commandline_arguments), 2):
- fields[commandline_arguments[i]] = commandline_arguments[i+1]
+ for i in xrange(0, len(commandline_arguments), 2):
+ fields[commandline_arguments[i]] = commandline_arguments[i + 1]
if templateTitle:
- gen = pagegenerators.ReferringPageGenerator(pywikibot.Page(pywikibot.getSite(),"Template:%s" % templateTitle ), onlyTemplateInclusion = True)
+ gen = pg.ReferringPageGenerator(pywikibot.Page(pywikibot.getSite(),
+ "Template:%s"
+ % templateTitle),
+ onlyTemplateInclusion=True)
else:
gen = genFactory.getCombinedGenerator()
if not gen:
# TODO: Build a transcluding generator based on templateTitle
return
-
+
bot = HarvestRobot(gen, templateTitle, fields)
bot.run()
Property changes on: trunk/pywikipedia/harvest_template.py
___________________________________________________________________
Added: svn:eol-style
+ native
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11691
Revision: 11691
Author: siebrand
Date: 2013-06-24 13:54:35 +0000 (Mon, 24 Jun 2013)
Log Message:
-----------
Localisation updates from http://translatewiki.net.
Modified Paths:
--------------
branches/rewrite/scripts/i18n/thirdparty.py
branches/rewrite/scripts/i18n/weblinkchecker.py
Modified: branches/rewrite/scripts/i18n/thirdparty.py
===================================================================
--- branches/rewrite/scripts/i18n/thirdparty.py 2013-06-23 06:54:21 UTC (rev 11690)
+++ branches/rewrite/scripts/i18n/thirdparty.py 2013-06-24 13:54:35 UTC (rev 11691)
@@ -377,6 +377,7 @@
# Author: Robin Owain
'cy': {
'thirdparty-drtrigonbot-sum_disc-summary-head': u'robot',
+ 'thirdparty-drtrigonbot-sum_disc-parse-nonhuman': u'(ni chafwyd hyd i olygydd dynol)',
'thirdparty-drtrigonbot-sum_disc-parse-warning': u':* Neges rhybuddio oddi wrth robot: %(page)s "\'\'%(warning)s\'\'"',
'thirdparty-drtrigonbot-sum_disc-notify-new': u'Trafodaeth newydd',
'thirdparty-drtrigonbot-sum_disc-parse-notify': u':* %(notify)s: <span class="plainlinks">[%(page_link)s %(page)s]</span> - y golygiad diweddaraf gan [[User:%(user)s]] (%(time)s)',
Modified: branches/rewrite/scripts/i18n/weblinkchecker.py
===================================================================
--- branches/rewrite/scripts/i18n/weblinkchecker.py 2013-06-23 06:54:21 UTC (rev 11690)
+++ branches/rewrite/scripts/i18n/weblinkchecker.py 2013-06-24 13:54:35 UTC (rev 11691)
@@ -182,6 +182,13 @@
'weblinkchecker-summary': u'Robot: Reporto de un ligamine externe non functionante',
'weblinkchecker-report': u'Durante plure sessiones automatic, le robot ha constatate que le sequente ligamine externe non es disponibile. Per favor confirma que le ligamine de facto es defuncte, e in caso de si, repara o elimina lo!',
},
+ # Author: Beta16
+ 'it': {
+ 'weblinkchecker-archive_msg': u'La pagina web è stata salvata da Internet Archive. Prendi in considerazione di collegare alla versione archiviata appropriata: [%(URL)s].',
+ 'weblinkchecker-caption': u'Link rotti',
+ 'weblinkchecker-summary': u'Bot: segnalo collegamenti esterni non raggiungibili',
+ 'weblinkchecker-report': u'Durante varie esecuzioni del bot i seguenti collegamenti esterni si sono rivelati non raggiungibili. Si prega di controllare se il link è effettivamente errato, quindi correggerlo o rimuoverlo.',
+ },
# Author: Shirayuki
'ja': {
'weblinkchecker-archive_msg': u'ウェブページはインターネットアーカイブに保存されました。アーカイブに保管された適切なバージョンにリンクすることを検討してください: [%(URL)s].',
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11686
Revision: 11686
Author: legoktm
Date: 2013-06-21 21:36:43 +0000 (Fri, 21 Jun 2013)
Log Message:
-----------
If the standard '*' message isn't available, use the 'html' one. Caused by [[bugzilla:49978]].
Modified Paths:
--------------
branches/rewrite/pywikibot/data/api.py
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2013-06-21 20:26:56 UTC (rev 11685)
+++ branches/rewrite/pywikibot/data/api.py 2013-06-21 21:36:43 UTC (rev 11686)
@@ -355,9 +355,18 @@
if "warnings" in result:
modules = [k for k in result["warnings"] if k != "info"]
for mod in modules:
+ if '*' in result["warnings"][mod]:
+ text = result["warnings"][mod]['*']
+ elif 'html' in result["warnings"][mod]:
+ # Bugzilla 49978
+ text = result["warnings"][mod]['html']['*']
+ else:
+ # This is just a warning, we shouldn't raise an
+ # exception because of it
+ continue
pywikibot.warning(
u"API warning (%s): %s"
- % (mod, result["warnings"][mod]["*"]))
+ % (mod, text))
if "error" not in result:
return result
if "*" in result["error"]:
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11685
Revision: 11685
Author: legoktm
Date: 2013-06-21 20:26:56 +0000 (Fri, 21 Jun 2013)
Log Message:
-----------
Refactor dimToPrecision function after discussion with valhallasw.
It now is a property that will be calculated as needed,
and uses a different formula written by valhallasw.
Follow up to r11682.
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2013-06-21 19:44:09 UTC (rev 11684)
+++ branches/rewrite/pywikibot/__init__.py 2013-06-21 20:26:56 UTC (rev 11685)
@@ -116,11 +116,11 @@
self.lat = lat
self.lon = lon
self.alt = alt
- self.precision = precision
+ self._precision = precision
self.globe = globe.lower()
self.type = typ
self.name = name
- self.dim = dim
+ self._dim = dim
if not site:
self.site = Site().data_repository()
else:
@@ -168,29 +168,27 @@
data['altitude'], data['precision'],
globes[data['globe']], site=site)
- def dimToPrecision(self):
- """Convert dim from GeoData to Wikibase's Precision
+ @property
+ def precision(self):
+ """
+ The biggest error (in degrees) will be given by the longitudinal error - the same error in meters becomes larger
+ (in degrees) further up north. We can thus ignore the latitudinal error.
- Formula from http://williams.best.vwh.net/avform.htm#LL and
- http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-lati…
+ The longitudinal can be derived as follows:
- THIS FUNCTION IS EXPERIMENTAL DO NOT USE IT!
- """
- lat_r = math.radians(self.lat)
- lon_r = math.radians(self.lon)
- radius = 6378137 # TODO: Support other globes
- offset = self.dim
- d_lat_r = offset / radius
- d_lon_r = offset / (radius * math.cos(math.pi * lat_r / 180))
+ In small angle approximation (and thus in radians):
- # Now convert to degrees
- lat_offset = math.degrees(d_lat_r)
- lon_offset = math.degrees(d_lon_r)
+ Δλ ≈ Δpos / r_φ, where r_φ is the radius of earth at the given latitude. Δλ is the error in longitude.
- # Take the average
- avg_offset = (lat_offset + lon_offset) / 2.0
- self.precision = avg_offset
+ r_φ = r cos φ, where r is the radius of earth, φ the latitude
+ Therefore: precision = math.degrees( self._dim / ( radius * math.cos( math.radians( self.lat ) ) ) )
+ """
+ if not self._precision:
+ radius = 6378137 # TODO: Support other globes
+ self._precision = math.degrees(self._dim / (radius * math.cos(math.radians(self.lat))))
+ return self._precision
+
def precisionToDim(self):
"""Convert precision from Wikibase to GeoData's dim"""
raise NotImplementedError