jenkins-bot has submitted this change and it was merged.
Change subject: Add lang argument where pywikibot.Site().language() was used
......................................................................
Add lang argument where pywikibot.Site().language() was used
The code previously set lang based on pywikibot defaults, which
meant you were limited to "nl" for erfgoedbot settings.
The code now requires that a -countrycode argument is always
accompanied by a -lang argument (where one was assumed).
Also raises an exception if an unexpected argument is recieved.
Change-Id: I2b653a195f15686223043f3c74b413bb7b5cf540
---
M erfgoedbot/add_coord_to_articles.py
M erfgoedbot/add_object_location_monuments.py
M erfgoedbot/categorize_images.py
M erfgoedbot/images_of_monuments_without_id.py
M erfgoedbot/missing_commonscat_links.py
M erfgoedbot/top_streets.py
M erfgoedbot/unused_monument_images.py
M erfgoedbot/update_database.py
M erfgoedbot/update_id_dump.py
9 files changed, 94 insertions(+), 23 deletions(-)
Approvals:
Jean-Frédéric: Looks good to me, approved
jenkins-bot: Verified
diff --git a/erfgoedbot/add_coord_to_articles.py
b/erfgoedbot/add_coord_to_articles.py
index 1a649b4..a6d024b 100644
--- a/erfgoedbot/add_coord_to_articles.py
+++ b/erfgoedbot/add_coord_to_articles.py
@@ -310,6 +310,7 @@
def main():
countrycode = u''
+ lang = u''
connMon = None
cursorMon = None
@@ -319,14 +320,22 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang "
+ "or pywikipediabot args.")
- if countrycode:
- lang = pywikibot.getSite().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(u'I have no config for countrycode "%s" in
language "%s"' % (countrycode, lang))
return False
pywikibot.output(u'Working on countrycode "%s" in language "%s"' %
(countrycode, lang))
processCountry(countrycode, lang, mconfig.countries.get((countrycode,
lang)), wikiData.get(lang), connMon, cursorMon)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
pywikibot.output(u'Working on countrycode "%s" in language "%s"' %
(countrycode, lang))
diff --git a/erfgoedbot/add_object_location_monuments.py
b/erfgoedbot/add_object_location_monuments.py
index 5b2676f..2e85b00 100644
--- a/erfgoedbot/add_object_location_monuments.py
+++ b/erfgoedbot/add_object_location_monuments.py
@@ -218,6 +218,7 @@
def main():
countrycode = u''
+ lang = u''
# Connect database, we need that
(conn, cursor) = connectDatabase()
@@ -230,11 +231,16 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang "
+ "or pywikipediabot args.")
- lang = pywikibot.getSite().language()
pywikibot.setSite(pywikibot.getSite(u'commons', u'commons'))
- if countrycode:
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -243,6 +249,9 @@
u'Working on countrycode "%s" in language "%s"' % (countrycode,
lang))
locateCountry(countrycode, lang, mconfig.countries.get(
(countrycode, lang)), conn, cursor, conn2, cursor2)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
if not countryconfig.get('autoGeocode'):
diff --git a/erfgoedbot/categorize_images.py b/erfgoedbot/categorize_images.py
index 80bbbb6..513b857 100644
--- a/erfgoedbot/categorize_images.py
+++ b/erfgoedbot/categorize_images.py
@@ -621,8 +621,8 @@
def main():
countrycode = u''
- overridecat = u''
lang = u''
+ overridecat = u''
conn = None
cursor = None
# Connect database, we need that
@@ -632,11 +632,16 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
elif option == '-overridecat':
overridecat = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang, -overridecat "
+ "or pywikipediabot args.")
- if countrycode:
- lang = pywikibot.Site().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -647,6 +652,9 @@
# print commonsCatTemplates
processCountry(countrycode, lang, mconfig.countries.get(
(countrycode, lang)), commonsCatTemplates, conn, cursor,
overridecat=overridecat)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
statistics = []
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
diff --git a/erfgoedbot/images_of_monuments_without_id.py
b/erfgoedbot/images_of_monuments_without_id.py
index d408210..6ab8bec 100644
--- a/erfgoedbot/images_of_monuments_without_id.py
+++ b/erfgoedbot/images_of_monuments_without_id.py
@@ -209,6 +209,7 @@
def main():
countrycode = u''
+ lang = u''
conn = None
cursor = None
# Connect database, we need that
@@ -219,10 +220,14 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang "
+ "or pywikipediabot args.")
- if countrycode:
- # looks like default lang is 'nl'
- lang = pywikibot.getSite().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -231,6 +236,9 @@
u'Working on countrycode "%s" in language "%s"' % (countrycode,
lang))
processCountry(countrycode, lang, mconfig.countries.get(
(countrycode, lang)), conn, cursor, conn2, cursor2)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
pywikibot.output(
diff --git a/erfgoedbot/missing_commonscat_links.py
b/erfgoedbot/missing_commonscat_links.py
index 8796bed..920e295 100644
--- a/erfgoedbot/missing_commonscat_links.py
+++ b/erfgoedbot/missing_commonscat_links.py
@@ -217,6 +217,7 @@
def main():
countrycode = u''
+ lang = u''
conn = None
cursor = None
# Connect database, we need that
@@ -227,9 +228,14 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang "
+ "or pywikipediabot args.")
- if countrycode:
- lang = pywikibot.Site().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -238,6 +244,9 @@
u'Working on countrycode "%s" in language "%s"' % (countrycode,
lang))
processCountry(countrycode, lang, mconfig.countries.get(
(countrycode, lang)), conn, cursor, conn2, cursor2)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
totals = {}
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
diff --git a/erfgoedbot/top_streets.py b/erfgoedbot/top_streets.py
index 137f987..ebc23b4 100644
--- a/erfgoedbot/top_streets.py
+++ b/erfgoedbot/top_streets.py
@@ -105,13 +105,18 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
elif option == '-municipality':
municipality = value
elif option == '-minimum':
minimum = int(value)
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang, -municipality,
-minimum "
+ "or pywikipediabot args.")
- if countrycode and municipality:
- lang = pywikibot.getSite().language()
+ if countrycode and lang and municipality:
addresses = getAddresses(countrycode, lang, municipality, conn, cursor)
printTopStreets(addresses, minimum)
else:
diff --git a/erfgoedbot/unused_monument_images.py
b/erfgoedbot/unused_monument_images.py
index 700ebb9..3afd3d3 100644
--- a/erfgoedbot/unused_monument_images.py
+++ b/erfgoedbot/unused_monument_images.py
@@ -209,6 +209,7 @@
def main():
countrycode = u''
+ lang = u''
conn = None
cursor = None
# Connect database, we need that
@@ -219,9 +220,14 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang "
+ "or pywikipediabot args.")
- if countrycode:
- lang = pywikibot.Site().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -230,6 +236,9 @@
u'Working on countrycode "%s" in language "%s"' % (countrycode,
lang))
processCountry(countrycode, lang, mconfig.countries.get(
(countrycode, lang)), conn, cursor, conn2, cursor2)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
totals = {}
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
diff --git a/erfgoedbot/update_database.py b/erfgoedbot/update_database.py
index 41ab724..e8e054a 100755
--- a/erfgoedbot/update_database.py
+++ b/erfgoedbot/update_database.py
@@ -461,6 +461,7 @@
# First find out what to work on
countrycode = u''
+ lang = u''
fullUpdate = True
daysBack = 2 # Default 2 days. Runs every night so can miss one night.
conn = None
@@ -471,16 +472,18 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
elif option == '-daysback':
daysBack = int(value)
- elif option == u'-fullupdate':
+ elif option == u'-fullupdate': # does nothing since this is already
default
fullUpdate = True
else:
raise Exception(
- "Bad parameters. Expected -countrycode, -daysback, -fullupdate
or pywikipediabot args.")
+ "Bad parameters. Expected -countrycode, -lang, -daysback, "
+ "-fullupdate or pywikipediabot args.")
- if countrycode:
- lang = pywikibot.Site().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -494,7 +497,9 @@
except Exception, e:
pywikibot.output("Unknown error occurred when processing country
%s in lang %s" % (countrycode, lang))
pywikibot.output(str(e))
-
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
pywikibot.output(
diff --git a/erfgoedbot/update_id_dump.py b/erfgoedbot/update_id_dump.py
index dde343c..1811a64 100755
--- a/erfgoedbot/update_id_dump.py
+++ b/erfgoedbot/update_id_dump.py
@@ -148,6 +148,7 @@
# First find out what to work on
countrycode = u''
+ lang = u''
textfile = u''
conn = None
cursor = None
@@ -157,14 +158,19 @@
option, sep, value = arg.partition(':')
if option == '-countrycode':
countrycode = value
+ elif option == '-lang':
+ lang = value
elif option == '-textfile':
textfile = value
+ else:
+ raise Exception(
+ "Bad parameters. Expected -countrycode, -lang, -textfile "
+ "or pywikipediabot args.")
query = u"""TRUNCATE table `id_dump`"""
cursor.execute(query)
- if countrycode:
- lang = pywikibot.getSite().language()
+ if countrycode and lang:
if not mconfig.countries.get((countrycode, lang)):
pywikibot.output(
u'I have no config for countrycode "%s" in language "%s"' %
(countrycode, lang))
@@ -178,6 +184,9 @@
else:
processCountry(
countrycode, lang, mconfig.countries.get((countrycode, lang)),
conn, cursor)
+ elif countrycode or lang:
+ raise Exception(
+ "The \"countrycode\" and \"lang\" arguments must be used
together.")
else:
for (countrycode, lang), countryconfig in
mconfig.countries.iteritems():
pywikibot.output(
--
To view, visit https://gerrit.wikimedia.org/r/287248
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2b653a195f15686223043f3c74b413bb7b5cf540
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <[email protected]>
Gerrit-Reviewer: Jean-Frédéric <[email protected]>
Gerrit-Reviewer: Lokal Profil <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits