jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/335364 )
Change subject: Harvest whether an image is geolocated in the image table
......................................................................
Harvest whether an image is geolocated in the image table
The `image` table in the database records all images that are
identified as depicting a monument (ie, having a monument id).
This adds a boolean column to the database to denote whether
an image is geotagged or not, and populates it during the
`populate_image_table` run.
Change-Id: I0477725279d3ace7d3b10fbfd5beaef77153b7e7
---
M erfgoedbot/populate_image_table.py
M erfgoedbot/sql/create_table_image.sql
2 files changed, 13 insertions(+), 4 deletions(-)
Approvals:
Lokal Profil: Looks good to me, approved
jenkins-bot: Verified
diff --git a/erfgoedbot/populate_image_table.py
b/erfgoedbot/populate_image_table.py
index 76f7a1b..760030f 100644
--- a/erfgoedbot/populate_image_table.py
+++ b/erfgoedbot/populate_image_table.py
@@ -93,7 +93,8 @@
monumentId = monumentId.lstrip(u'_')
# All uppercase, same happens in other list
# monumentId = monumentId.upper()
- updateImage(countrycode, monumentId, name, conn, cursor)
+ image_has_geolocation = has_geolocation(page_title)
+ updateImage(countrycode, monumentId, name, image_has_geolocation,
conn, cursor)
except UnicodeDecodeError:
pywikibot.output(
@@ -103,6 +104,13 @@
pywikibot.output(u'Got value error for %s' % (monumentId,))
return len(photos)
+
+
+def has_geolocation(page_title):
+ site = pywikibot.Site(u'commons', u'commons')
+ page = pywikibot.ImagePage(site, page_title)
+ geoloc_cat = pywikibot.Category(site, "Category:Media with locations")
+ return geoloc_cat in list(page.categories())
def getMonumentPhotos(commonsTrackerCategory, conn, cursor):
@@ -130,14 +138,14 @@
return result
-def updateImage(countrycode, monumentId, name, conn, cursor):
+def updateImage(countrycode, monumentId, name, has_geolocation, conn, cursor):
'''
Update an entry for a single image
'''
- query = u"""REPLACE INTO `image` (`country`, `id`, `img_name`) VALUES (%s,
%s, %s)"""
+ query = u"""REPLACE INTO `image` (`country`, `id`, `img_name`,
`has_geolocation`) VALUES (%s, %s, %s, %s)"""
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
- cursor.execute(query, (countrycode, monumentId, name,))
+ cursor.execute(query, (countrycode, monumentId, name,
has_geolocation,))
def makeStatistics(totals):
diff --git a/erfgoedbot/sql/create_table_image.sql
b/erfgoedbot/sql/create_table_image.sql
index 5c4714b..6063b4d 100644
--- a/erfgoedbot/sql/create_table_image.sql
+++ b/erfgoedbot/sql/create_table_image.sql
@@ -12,6 +12,7 @@
`country` varchar(10) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT
'',
`id` varchar(25) NOT NULL DEFAULT '0',
`img_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT
'',
+ `geoloc` boolean NOT NULL DEFAULT 0,
PRIMARY KEY (`country`,`id`, `img_name`),
KEY `country_id` (`country`,`id`),
KEY `img_name` (`img_name`)
--
To view, visit https://gerrit.wikimedia.org/r/335364
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0477725279d3ace7d3b10fbfd5beaef77153b7e7
Gerrit-PatchSet: 2
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Jean-Frédéric <[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