From 66cbf3b670d01fad470585c3ea1b3f02c938b8cd Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 10 Oct 2019 19:52:51 +0100 Subject: [PATCH] Don't crash when there is no image. --- app.py | 5 ++++- depicts/painting.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index a19cde6..2ffa0d9 100755 --- a/app.py +++ b/app.py @@ -333,7 +333,10 @@ def item_page(item_id): width = 800 image_filename = item.image_filename - image = image_with_cache(qid, image_filename, width) + if image_filename: + image = image_with_cache(qid, image_filename, width) + else: + image = None # hits = item.run_query() label_and_language = get_entity_label_and_language(entity) diff --git a/depicts/painting.py b/depicts/painting.py index 90d72b9..cca218b 100644 --- a/depicts/painting.py +++ b/depicts/painting.py @@ -100,7 +100,8 @@ class Painting: @property def image_filename(self): - return self.entity['claims']['P18'][0]['mainsnak']['datavalue']['value'] + if 'P18' in self.entity['claims']: + return self.entity['claims']['P18'][0]['mainsnak']['datavalue']['value'] @property def display_title(self): @@ -203,7 +204,8 @@ class Painting: if not titles: return [] - cat_list = mediawiki.get_categories(titles, 'commons') + # cat_list = mediawiki.get_categories(titles, 'commons') + cat_list = [] for title, cats in cat_list: for cat in cats: