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:


_______________________________________________
Pywikipedia-svn mailing list
Pywikipedia-svn@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to