XZise has submitted this change and it was merged.
Change subject: Validate WikidataBot .site and .repo
......................................................................
Validate WikidataBot .site and .repo
Bug: 72305
Change-Id: Iae6becc4173ba37b744f52e2db1268e1f07310ce
---
M pywikibot/bot.py
M scripts/claimit.py
M scripts/coordinate_import.py
M scripts/harvest_template.py
M scripts/illustrate_wikidata.py
M scripts/newitem.py
6 files changed, 12 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, approved
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 52a31c0..3389d10 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1049,6 +1049,14 @@
Source claims (P143) can be created for specific sites.
"""
+ def __init__(self, **kwargs):
+ super(WikidataBot, self).__init__(**kwargs)
+ self.site = pywikibot.Site()
+ self.repo = self.site.data_repository()
+ if self.repo is None:
+ raise pywikibot.exceptions.WikiBaseError(
+ '%s is not connected to a data repository' % self.site)
+
def cacheSources(self):
"""
Fetch the sources from the list on Wikidata.
diff --git a/scripts/claimit.py b/scripts/claimit.py
index d389c93..3d9d566 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -81,10 +81,10 @@
* exists_arg - String specifying how to handle duplicate claims
"""
+ super(ClaimRobot, self).__init__()
self.generator = generator
self.claims = claims
self.exists_arg = exists_arg
- self.repo = pywikibot.Site().data_repository()
self.cacheSources()
if self.exists_arg:
pywikibot.output('\'exists\' argument set to \'%s\''
% self.exists_arg)
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 71cef9c..cf82bf9 100644
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -43,8 +43,8 @@
* generator - A generator that yields Page objects.
"""
+ super(CoordImportRobot, self).__init__()
self.generator = pagegenerators.PreloadingGenerator(generator)
- self.repo = pywikibot.Site().data_repository()
self.cacheSources()
self.prop = 'P625'
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 13ce7cf..cbfa774 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -53,11 +53,11 @@
* fields - A dictionary of fields that are of use to us
"""
+ super(HarvestRobot, self).__init__()
self.generator = pg.PreloadingGenerator(generator)
self.templateTitle = templateTitle.replace(u'_', u' ')
# TODO: Make it a list which also includes the redirects to the template
self.fields = fields
- self.repo = pywikibot.Site().data_repository()
self.cacheSources()
self.templateTitles = self.getTemplateSynonyms(self.templateTitle)
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index 0a4dc1c..84454bb 100644
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -40,9 +40,9 @@
* wdproperty - The property to add. Should be of type commonsMedia
"""
+ super(IllustrateRobot, self).__init__()
self.generator = pg.PreloadingGenerator(generator)
self.wdproperty = wdproperty
- self.repo = pywikibot.Site().data_repository()
self.cacheSources()
claim = pywikibot.Claim(self.repo, self.wdproperty)
diff --git a/scripts/newitem.py b/scripts/newitem.py
index b6ea11f..8d6ec2b 100644
--- a/scripts/newitem.py
+++ b/scripts/newitem.py
@@ -46,7 +46,6 @@
super(NewItemRobot, self).__init__(**kwargs)
self.generator = pagegenerators.PreloadingGenerator(generator)
- self.repo = pywikibot.Site().data_repository()
self.pageAge = self.getOption('pageage')
self.lastEdit = self.getOption('lastedit')
self.pageAgeBefore = self.repo.getcurrenttime() - timedelta(days=self.pageAge)
--
To view, visit
https://gerrit.wikimedia.org/r/167793
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iae6becc4173ba37b744f52e2db1268e1f07310ce
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>