Better image filename handling

This commit is contained in:
Edward Betts 2020-06-30 09:00:58 +01:00
parent 97e4501427
commit 9299909e2f

4
app.py
View file

@ -345,13 +345,15 @@ def image_with_cache(qid, image_filename, width):
filename = f'cache/{qid}_{width}_image.json'
detail = json.load(open(filename)) if os.path.exists(filename) else {}
image_filename = image_filename.replace('_', ' ')
# The image associated with an item can change.
# If that happens the detail in the cache will be for the wrong file.
if not detail or image_filename not in detail:
detail = commons.image_detail([image_filename], thumbwidth=width)
json.dump(detail, open(filename, 'w'), indent=2)
return detail[image_filename]
return detail.get(image_filename)
def existing_depicts_from_entity(entity):
if 'P180' not in entity['claims']: