http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11581
Revision: 11581
Author: valhallasw
Date: 2013-05-25 14:12:30 +0000 (Sat, 25 May 2013)
Log Message:
-----------
(for rewrite) New script to replicate wiki pages, contributed by Kasper Souren
This script allows you to replicate all pages in a certain namespace
to a second wiki. You can, for instance, use this to keep templates
or semantic forms synchronised from a master wiki.
Modified Paths:
--------------
branches/rewrite/pywikibot/config2.py
Added Paths:
-----------
branches/rewrite/scripts/replicate_wiki.py
Modified: branches/rewrite/pywikibot/config2.py
===================================================================
--- branches/rewrite/pywikibot/config2.py 2013-05-25 14:03:33 UTC (rev 11580)
+++ branches/rewrite/pywikibot/config2.py 2013-05-25 14:12:30 UTC (rev 11581)
@@ -523,6 +523,17 @@
# cosmetic_changes_deny_script.append('your_script_name')
cosmetic_changes_deny_script = ['cosmetic_changes', 'touch']
+############## REPLICATION BOT ################
+# You can add replicate_replace to your user_config.py, which has the following format:
+#
+# replicate_replace = {
+# 'wikipedia:li': {'Hoofdpagina': 'Veurblaad'}
+# }
+#
+# to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to liwiki. Note that this does
+# not take the origin wiki into account.
+replicate_replace = {}
+
############## FURTHER SETTINGS ##############
### Proxy configuration ###
Added: branches/rewrite/scripts/replicate_wiki.py
===================================================================
--- branches/rewrite/scripts/replicate_wiki.py (rev 0)
+++ branches/rewrite/scripts/replicate_wiki.py 2013-05-25 14:12:30 UTC (rev 11581)
@@ -0,0 +1,233 @@
+#!/usr/bin/env python
+#
+# -*- coding: utf-8 -*-
+#
+# (C) Kasper Souren 2012-2013
+#
+# Distributed under the terms of the MIT license.
+#
+
+'''
+This bot replicates all pages (from specific namespaces) in a wiki to a second wiki within one family.
+
+Example:
+python replicate_wiki.py [-r] -ns 10 -f wikipedia -o nl li fy
+
+to copy all templates from an nlwiki to liwiki and fywiki. It will show which pages have to be changed
+if -r is not present, and will only actually write pages if -r /is/ present.
+
+You can add replicate_replace to your user_config.py, which has the following format:
+
+replicate_replace = {
+ 'wikipedia:li': {'Hoofdpagina': 'Veurblaad'}
+}
+
+to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to liwiki. Note that this does
+not take the origin wiki into account.
+'''
+
+import sys
+import re
+from pywikibot import *
+from itertools import imap
+
+def namespaces(site):
+ '''dict from namespace number to prefix'''
+ ns = dict(map(lambda n: (site.getNamespaceIndex(n), n),
+ site.namespaces()))
+ ns[0] = ''
+ return ns
+
+
+def multiple_replace(text, word_dict):
+ '''Replace all occurrences in text of key value pairs in word_dict'''
+ for key in word_dict:
+ text = text.replace(key, word_dict[key])
+ return text
+
+
+class SyncSites:
+ '''Work is done in here.'''
+
+ def __init__(self, options):
+ self.options = options
+
+ if options.original_wiki:
+ original_wiki = options.original_wiki
+ else:
+ original_wiki = config.mylang
+
+ print "Syncing from " + original_wiki
+
+ family = options.family or config.family
+
+ sites = options.destination_wiki
+
+ self.original = getSite(original_wiki, family)
+
+ if options.namespace and 'help' in options.namespace:
+ nsd = namespaces(self.original)
+ for k in nsd:
+ print k, nsd[k]
+ sys.exit()
+
+ self.sites = map(lambda s: getSite(s, family), sites)
+
+ self.differences = {}
+ self.user_diff = {}
+ print 'Syncing to',
+ for s in self.sites:
+ self.differences[s] = []
+ self.user_diff[s] = []
+ print s,
+ print
+
+ def check_sysops(self):
+ '''Check if sysops are the same
+
+ TODO: implement for API and make optional
+ '''
+ #def get_users(site):
+ # userlist = site.getUrl(site.get_address('Special:Userlist&group=sysop'))
+ # # Hackery but working. At least on MW 1.15.0
+ # # User namespace is number 2
+ # return set(re.findall(site.namespace(2) + ':(\w+)["\&]', userlist))
+ #
+ #ref_users = get_users(self.original)
+ #for site in self.sites:
+ # users = get_users(site)
+ # diff = list(ref_users.difference(users))
+ # diff.sort()
+ # self.user_diff[site] = diff
+
+ def check_namespaces(self):
+ '''Check all namespaces, to be ditched for clarity'''
+ namespaces = [
+ 0, # Main
+ 8, # MediaWiki
+ 152, # DPL
+ 102, # Eigenschap
+ 104, # Type
+ 106, # Formulier
+ 108, # Concept
+ 10, # Sjabloon
+ ]
+
+ if self.options.namespace:
+ print options.namespace
+ namespaces = [int(options.namespace)]
+ print "Checking these namespaces", namespaces, "\n"
+
+ for ns in namespaces:
+ self.check_namespace(ns)
+
+ def check_namespace(self, namespace):
+ '''Check an entire namespace'''
+
+ print "\nCHECKING NAMESPACE", namespace
+ pages = imap(lambda p: p.title(),
+ self.original.allpages('!', namespace=namespace))
+ for p in pages:
+ if not p in ['MediaWiki:Sidebar', 'MediaWiki:Mainpage',
+ 'MediaWiki:Sitenotice', 'MediaWiki:MenuSidebar']:
+ try:
+ self.check_page(p)
+ except pywikibot.exceptions.NoPage:
+ print 'Bizarre NoPage exception that we are just going to ignore'
+ except pywikibot.exceptions.IsRedirectPage:
+ print 'error: Redirectpage - todo: handle gracefully'
+ print
+
+
+ def generate_overviews(self):
+ '''Create page on wikis with overview of bot results'''
+ for site in self.sites:
+ sync_overview_page = Page(site, 'User:' + site.loggedInAs() + '/sync.py overview')
+ output = "== Pages that differ from original ==\n\n"
+ if self.differences[site]:
+ output += "".join(map(lambda l: '* [[:' + l + "]]\n", self.differences[site]))
+ else:
+ output += "All important pages are the same"
+
+ output += "\n\n== Admins from original that are missing here ==\n\n"
+ if self.user_diff[site]:
+ output += "".join(map(lambda l: '* ' + l.replace('_', ' ') + "\n", self.user_diff[site]))
+ else:
+ output += "All users from original are also present on this wiki"
+
+ print output
+ sync_overview_page.put(output, self.put_message(site))
+
+
+ def put_message(self, site):
+ return site.loggedInAs() + ' sync.py synchronization from ' + str(self.original)
+
+ def check_page(self, pagename):
+ '''Check one page'''
+
+ print "\nChecking", pagename,
+ sys.stdout.flush()
+ page1 = Page(self.original, pagename)
+ txt1 = page1.get()
+
+ for site in self.sites:
+ if options.dest_namespace:
+ prefix = namespaces(site)[int(options.dest_namespace)]
+ if prefix:
+ prefix += ':'
+ new_pagename = prefix + page1.titleWithoutNamespace()
+ print "\nCross namespace, new title: ", new_pagename
+ else:
+ new_pagename = pagename
+
+ page2 = Page(site, new_pagename)
+ if page2.exists():
+ txt2 = page2.get()
+
+ else:
+ txt2 = ''
+
+ if config.replicate_replace.has_key(str(site)):
+ txt_new = multiple_replace(txt1, config.replicate_replace[str(site)])
+ if txt1 != txt_new:
+ print 'NOTE: text replaced using config.sync_replace'
+ print txt1, txt_new, txt2
+ txt1 = txt_new
+
+ if txt1 != txt2:
+ print "\n", site, 'DIFFERS'
+ self.differences[site].append(pagename)
+
+ if self.options.replace:
+ page2.put(txt1, self.put_message(site))
+ else:
+ sys.stdout.write('.')
+ sys.stdout.flush()
+
+
+if __name__ == '__main__':
+ from argparse import ArgumentParser
+
+ parser = ArgumentParser()
+ parser.add_argument("-f", "--family", dest="family",
+ help="wiki family")
+
+ parser.add_argument("-r", "--replace", action="store_true",
+ help="actually replace pages (without this option you will only get an overview page)")
+ parser.add_argument("-o", "--original", dest="original_wiki",
+ help="original wiki")
+ parser.add_argument('destination_wiki', metavar='N', type=str, nargs='+',
+ help='destination wiki(s)')
+ parser.add_argument("-ns", "--namespace", dest="namespace",
+ help="specify namespace")
+ parser.add_argument("-dns", "--dest-namespace", dest="dest_namespace",
+ help="destination namespace (if different)")
+
+ (options, args) = parser.parse_known_args()
+
+ # sync is global for convenient IPython debugging
+ sync = SyncSites(options)
+ sync.check_sysops()
+ sync.check_namespaces()
+ sync.generate_overviews()
+
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11580
Revision: 11580
Author: valhallasw
Date: 2013-05-25 14:03:33 +0000 (Sat, 25 May 2013)
Log Message:
-----------
New script to replicate wiki pages, contributed by Kasper Souren
This script allows you to replicate all pages in a certain namespace
to a second wiki. You can, for instance, use this to keep templates
or semantic forms synchronised from a master wiki.
Modified Paths:
--------------
trunk/pywikipedia/config.py
Added Paths:
-----------
trunk/pywikipedia/replicate_wiki.py
Modified: trunk/pywikipedia/config.py
===================================================================
--- trunk/pywikipedia/config.py 2013-05-25 09:26:38 UTC (rev 11579)
+++ trunk/pywikipedia/config.py 2013-05-25 14:03:33 UTC (rev 11580)
@@ -438,6 +438,18 @@
# number of results.
copyright_economize_query = True
+############## REPLICATION BOT ################
+# You can add replicate_replace to your user_config.py, which has the following format:
+#
+# replicate_replace = {
+# 'wikipedia:li': {'Hoofdpagina': 'Veurblaad'}
+# }
+#
+# to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to liwiki. Note that this does
+# not take the origin wiki into account.
+replicate_replace = {}
+
+
############## HTTP SETTINGS ##############
# Default socket timeout. Set to None to disable timeouts.
socket_timeout = 120 # set a pretty long timeout just in case...
Added: trunk/pywikipedia/replicate_wiki.py
===================================================================
--- trunk/pywikipedia/replicate_wiki.py (rev 0)
+++ trunk/pywikipedia/replicate_wiki.py 2013-05-25 14:03:33 UTC (rev 11580)
@@ -0,0 +1,233 @@
+#!/usr/bin/env python
+#
+# -*- coding: utf-8 -*-
+#
+# (C) Kasper Souren 2012-2013
+#
+# Distributed under the terms of the MIT license.
+#
+
+'''
+This bot replicates all pages (from specific namespaces) in a wiki to a second wiki within one family.
+
+Example:
+python replicate_wiki.py [-r] -ns 10 -f wikipedia -o nl li fy
+
+to copy all templates from an nlwiki to liwiki and fywiki. It will show which pages have to be changed
+if -r is not present, and will only actually write pages if -r /is/ present.
+
+You can add replicate_replace to your user_config.py, which has the following format:
+
+replicate_replace = {
+ 'wikipedia:li': {'Hoofdpagina': 'Veurblaad'}
+}
+
+to replace all occurences of 'Hoofdpagina' with 'Veurblaad' when writing to liwiki. Note that this does
+not take the origin wiki into account.
+'''
+
+import sys
+import re
+from wikipedia import *
+from itertools import imap
+
+def namespaces(site):
+ '''dict from namespace number to prefix'''
+ ns = dict(map(lambda n: (site.getNamespaceIndex(n), n),
+ site.namespaces()))
+ ns[0] = ''
+ return ns
+
+
+def multiple_replace(text, word_dict):
+ '''Replace all occurrences in text of key value pairs in word_dict'''
+ for key in word_dict:
+ text = text.replace(key, word_dict[key])
+ return text
+
+
+class SyncSites:
+ '''Work is done in here.'''
+
+ def __init__(self, options):
+ self.options = options
+
+ if options.original_wiki:
+ original_wiki = options.original_wiki
+ else:
+ original_wiki = config.mylang
+
+ print "Syncing from " + original_wiki
+
+ family = options.family or config.family
+
+ sites = options.destination_wiki
+
+ self.original = getSite(original_wiki, family)
+
+ if options.namespace and 'help' in options.namespace:
+ nsd = namespaces(self.original)
+ for k in nsd:
+ print k, nsd[k]
+ sys.exit()
+
+ self.sites = map(lambda s: getSite(s, family), sites)
+
+ self.differences = {}
+ self.user_diff = {}
+ print 'Syncing to',
+ for s in self.sites:
+ self.differences[s] = []
+ self.user_diff[s] = []
+ print s,
+ print
+
+ def check_sysops(self):
+ '''Check if sysops are the same
+
+ TODO: make optional
+ '''
+ def get_users(site):
+ userlist = site.getUrl(site.get_address('Special:Userlist&group=sysop'))
+ # Hackery but working. At least on MW 1.15.0
+ # User namespace is number 2
+ return set(re.findall(site.namespace(2) + ':(\w+)["\&]', userlist))
+
+ ref_users = get_users(self.original)
+ for site in self.sites:
+ users = get_users(site)
+ diff = list(ref_users.difference(users))
+ diff.sort()
+ self.user_diff[site] = diff
+
+ def check_namespaces(self):
+ '''Check all namespaces, to be ditched for clarity'''
+ namespaces = [
+ 0, # Main
+ 8, # MediaWiki
+ 152, # DPL
+ 102, # Eigenschap
+ 104, # Type
+ 106, # Formulier
+ 108, # Concept
+ 10, # Sjabloon
+ ]
+
+ if self.options.namespace:
+ print options.namespace
+ namespaces = [int(options.namespace)]
+ print "Checking these namespaces", namespaces, "\n"
+
+ for ns in namespaces:
+ self.check_namespace(ns)
+
+ def check_namespace(self, namespace):
+ '''Check an entire namespace'''
+
+ print "\nCHECKING NAMESPACE", namespace
+ pages = imap(lambda p: p.title(),
+ self.original.allpages('!', namespace))
+ for p in pages:
+ if not p in ['MediaWiki:Sidebar', 'MediaWiki:Mainpage',
+ 'MediaWiki:Sitenotice', 'MediaWiki:MenuSidebar']:
+ try:
+ self.check_page(p)
+ except pywikibot.exceptions.NoPage:
+ print 'Bizarre NoPage exception that we are just going to ignore'
+ except pywikibot.exceptions.IsRedirectPage:
+ print 'error: Redirectpage - todo: handle gracefully'
+ print
+
+
+ def generate_overviews(self):
+ '''Create page on wikis with overview of bot results'''
+ for site in self.sites:
+ sync_overview_page = Page(site, 'User:' + site.loggedInAs() + '/sync.py overview')
+ output = "== Pages that differ from original ==\n\n"
+ if self.differences[site]:
+ output += "".join(map(lambda l: '* [[:' + l + "]]\n", self.differences[site]))
+ else:
+ output += "All important pages are the same"
+
+ output += "\n\n== Admins from original that are missing here ==\n\n"
+ if self.user_diff[site]:
+ output += "".join(map(lambda l: '* ' + l.replace('_', ' ') + "\n", self.user_diff[site]))
+ else:
+ output += "All users from original are also present on this wiki"
+
+ print output
+ sync_overview_page.put(output, self.put_message(site))
+
+
+ def put_message(self, site):
+ return site.loggedInAs() + ' sync.py synchronization from ' + str(self.original)
+
+ def check_page(self, pagename):
+ '''Check one page'''
+
+ print "\nChecking", pagename,
+ sys.stdout.flush()
+ page1 = Page(self.original, pagename)
+ txt1 = page1.get()
+
+ for site in self.sites:
+ if options.dest_namespace:
+ prefix = namespaces(site)[int(options.dest_namespace)]
+ if prefix:
+ prefix += ':'
+ new_pagename = prefix + page1.titleWithoutNamespace()
+ print "\nCross namespace, new title: ", new_pagename
+ else:
+ new_pagename = pagename
+
+ page2 = Page(site, new_pagename)
+ if page2.exists():
+ txt2 = page2.get()
+
+ else:
+ txt2 = ''
+
+ if config.replicate_replace.has_key(str(site)):
+ txt_new = multiple_replace(txt1, config.replicate_replace[str(site)])
+ if txt1 != txt_new:
+ print 'NOTE: text replaced using config.sync_replace'
+ print txt1, txt_new, txt2
+ txt1 = txt_new
+
+ if txt1 != txt2:
+ print "\n", site, 'DIFFERS'
+ self.differences[site].append(pagename)
+
+ if self.options.replace:
+ page2.put(txt1, self.put_message(site))
+ else:
+ sys.stdout.write('.')
+ sys.stdout.flush()
+
+
+if __name__ == '__main__':
+ from argparse import ArgumentParser
+
+ parser = ArgumentParser()
+ parser.add_argument("-f", "--family", dest="family",
+ help="wiki family")
+
+ parser.add_argument("-r", "--replace", action="store_true",
+ help="actually replace pages (without this option you will only get an overview page)")
+ parser.add_argument("-o", "--original", dest="original_wiki",
+ help="original wiki")
+ parser.add_argument('destination_wiki', metavar='N', type=str, nargs='+',
+ help='destination wiki(s)')
+ parser.add_argument("-ns", "--namespace", dest="namespace",
+ help="specify namespace")
+ parser.add_argument("-dns", "--dest-namespace", dest="dest_namespace",
+ help="destination namespace (if different)")
+
+ (options, args) = parser.parse_known_args()
+
+ # sync is global for convenient IPython debugging
+ sync = SyncSites(options)
+ sync.check_sysops()
+ sync.check_namespaces()
+ sync.generate_overviews()
+
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11575
Revision: 11575
Author: valhallasw
Date: 2013-05-24 14:52:50 +0000 (Fri, 24 May 2013)
Log Message:
-----------
+ auto-generate user files if they do not exist yet
Modified Paths:
--------------
branches/rewrite/pwb.py
Modified: branches/rewrite/pwb.py
===================================================================
--- branches/rewrite/pwb.py 2013-05-24 08:29:32 UTC (rev 11574)
+++ branches/rewrite/pwb.py 2013-05-24 14:52:50 UTC (rev 11575)
@@ -31,6 +31,9 @@
if "PYWIKIBOT2_DIR" not in os.environ:
os.environ["PYWIKIBOT2_DIR"] = os.path.split(__file__)[0]
+if not os.path.exists(os.path.join(os.environ["PYWIKIBOT2_DIR"], "user-config.py")):
+ execfile('generate_user_files.py')
+
sys.argv.pop(0)
if len(sys.argv) > 0:
if not os.path.exists(sys.argv[0]):
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11574
Revision: 11574
Author: amir
Date: 2013-05-24 08:29:32 +0000 (Fri, 24 May 2013)
Log Message:
-----------
Adding harvset_template from rewrite branch with some setting special for trunk. I tested it and It worked
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Added Paths:
-----------
trunk/pywikipedia/harvest_template.py
Added: trunk/pywikipedia/harvest_template.py
===================================================================
--- trunk/pywikipedia/harvest_template.py (rev 0)
+++ trunk/pywikipedia/harvest_template.py 2013-05-24 08:29:32 UTC (rev 11574)
@@ -0,0 +1,157 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+Copyright (C) 2013 Multichill, Amir
+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
+
+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
+
+"""
+import re
+import wikipedia as pywikibot
+import pagegenerators
+
+class HarvestRobot:
+ """
+ A bot to add Wikidata claims
+ """
+ def __init__(self, generator, templateTitle, fields):
+ """
+ Arguments:
+ * generator - A generator that yields Page objects.
+ * templateTitle - The template to work on
+ * fields - A dictionary of fields that are of use to us
+
+ """
+ self.generator = generator
+ self.templateTitle = templateTitle.replace(u'_', u' ')
+ self.pregen=pagegenerators.PreloadingGenerator(generator)
+ self.fields = fields
+ self.site=pywikibot.getSite()
+ self.repo = self.site.data_repository()
+
+ def setSource(self, lang):
+ '''
+ Get the source
+ '''
+ source_values = {'en': 'Q328',
+ 'sv': 'Q169514',
+ 'de': 'Q48183',
+ 'it': 'Q11920',
+ 'no': 'Q191769',
+ 'fa': 'Q48952',
+ 'ar': 'Q199700',
+ 'es': 'Q8449',
+ 'pl': 'Q1551807',
+ 'ca': 'Q199693',
+ 'fr': 'Q8447',
+ 'nl': 'Q10000',
+ 'pt': 'Q11921',
+ 'ru': 'Q206855',
+ 'vi': 'Q200180',
+ 'be': 'Q877583',
+ 'uk': 'Q199698',
+ 'tr': 'Q58255',
+ } # TODO: Should be moved to a central wikidata library
+
+ if lang in source_values:
+ source = ('143',source_values.get(lang))
+ return source
+ else:
+ return None
+
+ def run(self):
+ """
+ Starts the robot.
+ """
+ for page in self.pregen:
+ self.procesPage(page)
+
+ def procesPage(self, page):
+ """
+ Proces a single page
+ """
+ item = pywikibot.DataPage(page)
+ pywikibot.output('Processing %s' % page)
+ if not item.exists():
+ pywikibot.output('%s doesn\'t have a wikidata item :(' % page)
+ #TODO FIXME: We should provide an option to create the page
+ else:
+ pagetext = page.get()
+ pagetext = pywikibot.removeDisabledParts(pagetext)
+ 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:
+ 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]
+ 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
+ else:
+ # Try to extract a valid page
+ match = re.search(re.compile(r'\[\[(?P<title>[^\]|[#<>{}]*)(\|.*?)?\]\]'), value)
+ if match:
+ try:
+ link = match.group(1)
+ linkedPage = pywikibot.Page(self.site, link)
+ if linkedPage.isRedirectPage():
+ linkedPage = linkedPage.getRedirectTarget()
+ linkedItem = pywikibot.DataPage(linkedPage)
+ 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())})
+ else:
+ item.editclaim(str(claim), linkedItem.getID() )
+ except pywikibot.NoPage:
+ pywikibot.output('[[%s]] doesn\'t exist so I can\'t link to it' % (linkedItem.title(),))
+
+
+def main():
+ genFactory = pagegenerators.GeneratorFactory()
+ commandline_arguments = list()
+ templateTitle = u''
+ for arg in pywikibot.handleArgs():
+ if arg.startswith('-template'):
+ if len(arg) == 9:
+ templateTitle = pywikibot.input(
+ u'Please enter the template to work on:')
+ else:
+ templateTitle = arg[10:]
+ elif genFactory.handleArg(arg):
+ 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]
+ if templateTitle:
+ gen = pagegenerators.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()
+
+if __name__ == "__main__":
+ main()
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-05-24 08:00:04 UTC (rev 11573)
+++ trunk/pywikipedia/wikipedia.py 2013-05-24 08:29:32 UTC (rev 11574)
@@ -4050,7 +4050,9 @@
self._siteTitle=self._originSite.dbName().split('_')[0].replace("-","_")
if not (self._originSite == source):
self._title = None
-
+ def getID(self):
+ items=self.get()
+ return int(self.title()[1:])
def setitem(self, summary=None, watchArticle=False, minorEdit=True,
newPage=False, token=None, newToken=False, sysop=False,
captcha=None, botflag=True, maxTries=-1, items={}):