Compare commits

..

No commits in common. "be6e1a86d7c1d771f69067e0aa6b9feb4f2a3a55" and "52db7ac00f340354c8e629b539f758d6579feedc" have entirely different histories.

6 changed files with 509 additions and 673 deletions

978
app.py

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,7 @@ def image_detail(filenames, thumbheight=None, thumbwidth=None):
call_params = params.copy() call_params = params.copy()
call_params['titles'] = '|'.join(f'File:{f}' for f in cur) call_params['titles'] = '|'.join(f'File:{f}' for f in cur)
r = mediawiki.api_post(call_params, api_url=commons_url) r = mediawiki.api_call(call_params, api_url=commons_url)
for image in r.json()['query']['pages']: for image in r.json()['query']['pages']:
filename = utils.drop_start(image['title'], 'File:') filename = utils.drop_start(image['title'], 'File:')

View file

@ -1,24 +1,16 @@
import logging import logging
from logging.handlers import SMTPHandler from logging.handlers import SMTPHandler
from logging import Formatter from logging import Formatter
from flask import request, g from flask import request
PROJECT = 'depicts' PROJECT = 'depicts'
class MatcherSMTPHandler(SMTPHandler): class MatcherSMTPHandler(SMTPHandler):
def getSubject(self, record): # noqa: N802 def getSubject(self, record): # noqa: N802
subject = (f'{PROJECT} error: {record.exc_info[0].__name__}' return (f'{PROJECT} error: {record.exc_info[0].__name__}'
if (record.exc_info and record.exc_info[0]) if (record.exc_info and record.exc_info[0])
else f'{PROJECT} error: {record.pathname}:{record.lineno:d}') else f'{PROJECT} error: {record.pathname}:{record.lineno:d}')
if qid := getattr(g, 'qid', None):
subject += f' {qid}'
if label := getattr(g, 'label', None):
subject += f': {label}'
return subject
class RequestFormatter(Formatter): class RequestFormatter(Formatter):
def format(self, record): def format(self, record):
record.request = request record.request = request

View file

@ -39,7 +39,7 @@ def from_name(name):
found = [] found = []
for entity in mediawiki.get_entities_with_cache(qids, props='labels|descriptions'): for entity in mediawiki.get_entities_with_cache(qids, props='labels|descriptions'):
if 'redirects' in entity or 'missing' in entity: if 'redirects' in entity:
continue continue
qid = entity['id'] qid = entity['id']
item = lookup[qid] item = lookup[qid]
@ -51,7 +51,7 @@ def from_name(name):
label = wikibase.get_entity_label(entity) label = wikibase.get_entity_label(entity)
if label: if label:
i['label'] = label i['label'] = label
if 'en' in entity.get('descriptions', {}): if 'en' in entity['descriptions']:
i['description'] = entity['descriptions']['en']['value'] i['description'] = entity['descriptions']['en']['value']
found.append(i) found.append(i)
found.sort(key=lambda i: i.get('label', '')) found.sort(key=lambda i: i.get('label', ''))

View file

@ -24,16 +24,6 @@ def api_call(params, api_url=wikidata_url):
r = requests.get(api_url, params=call_params, timeout=5) r = requests.get(api_url, params=call_params, timeout=5)
return r return r
def api_post(params, api_url=wikidata_url):
call_params = {
'format': 'json',
'formatversion': 2,
**params,
}
r = requests.post(api_url, data=call_params, timeout=5)
return r
def get_list(list_name, **params): def get_list(list_name, **params):
r = api_call({'action': 'query', 'list': list_name, **params}) r = api_call({'action': 'query', 'list': list_name, **params})
return r.json()['query'][list_name] return r.json()['query'][list_name]

View file

@ -153,15 +153,12 @@ def check_catalog(entity, catalog):
catalog.update(cat) catalog.update(cat)
return return
try:
html = get_catalog_url(catalog_url) html = get_catalog_url(catalog_url)
if html: if html:
description = get_description_from_page(html) description = get_description_from_page(html)
if description: if description:
catalog['description'] = description catalog['description'] = description
return return
except UnicodeDecodeError:
return
for property_id in sorted(catalog_ids): for property_id in sorted(catalog_ids):
if property_id == 'P350': if property_id == 'P350':
@ -206,8 +203,7 @@ def get_catalog_from_artwork(entity):
check_catalog(entity, catalog) check_catalog(entity, catalog)
except (requests.exceptions.ReadTimeout, except (requests.exceptions.ReadTimeout,
requests.exceptions.ConnectTimeout, requests.exceptions.ConnectTimeout,
requests.exceptions.ConnectionError, requests.exceptions.ConnectionError):
requests.exceptions.TooManyRedirects):
pass pass
return catalog return catalog