Pick a new random painting

Make sure that a randomly chosen painting hasn't been shown before and
has no depicts statements.
This commit is contained in:
Edward Betts 2019-10-07 10:34:53 +01:00
parent ec4cb0e987
commit 9e8342b0ec

9
app.py
View file

@ -283,8 +283,13 @@ def start():
@app.route('/next') @app.route('/next')
def random_painting(): def random_painting():
rows = wdqs.run_query_with_cache(painting_no_depicts_query) rows = wdqs.run_query_with_cache(painting_no_depicts_query)
row = random.choice(rows) has_depicts = True
item_id = wdqs.row_id(row) while has_depicts:
item_id = wdqs.row_id(random.choice(rows))
if PaintingItem.query.get(item_id):
continue
has_depicts = 'P180' in mediawiki.get_entity(f'Q{item_id}')['claims']
return redirect(url_for('item_page', item_id=item_id)) return redirect(url_for('item_page', item_id=item_id))
@app.route('/oauth/start') @app.route('/oauth/start')