Compare commits
10 commits
52db7ac00f
...
be6e1a86d7
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | be6e1a86d7 | ||
Edward Betts | df0138df4a | ||
Edward Betts | cb3a9396de | ||
Edward Betts | 60bb9febd9 | ||
Edward Betts | ee61843183 | ||
Edward Betts | 845666dd5a | ||
Edward Betts | 8c715fe148 | ||
Edward Betts | 117459bb8f | ||
Edward Betts | 98d84054d6 | ||
Edward Betts | dc4455bec5 |
|
@ -25,7 +25,7 @@ def image_detail(filenames, thumbheight=None, thumbwidth=None):
|
|||
call_params = params.copy()
|
||||
call_params['titles'] = '|'.join(f'File:{f}' for f in cur)
|
||||
|
||||
r = mediawiki.api_call(call_params, api_url=commons_url)
|
||||
r = mediawiki.api_post(call_params, api_url=commons_url)
|
||||
|
||||
for image in r.json()['query']['pages']:
|
||||
filename = utils.drop_start(image['title'], 'File:')
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
import logging
|
||||
from logging.handlers import SMTPHandler
|
||||
from logging import Formatter
|
||||
from flask import request
|
||||
from flask import request, g
|
||||
|
||||
PROJECT = 'depicts'
|
||||
|
||||
class MatcherSMTPHandler(SMTPHandler):
|
||||
def getSubject(self, record): # noqa: N802
|
||||
return (f'{PROJECT} error: {record.exc_info[0].__name__}'
|
||||
if (record.exc_info and record.exc_info[0])
|
||||
else f'{PROJECT} error: {record.pathname}:{record.lineno:d}')
|
||||
subject = (f'{PROJECT} error: {record.exc_info[0].__name__}'
|
||||
if (record.exc_info and record.exc_info[0])
|
||||
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):
|
||||
def format(self, record):
|
||||
|
|
|
@ -39,7 +39,7 @@ def from_name(name):
|
|||
|
||||
found = []
|
||||
for entity in mediawiki.get_entities_with_cache(qids, props='labels|descriptions'):
|
||||
if 'redirects' in entity:
|
||||
if 'redirects' in entity or 'missing' in entity:
|
||||
continue
|
||||
qid = entity['id']
|
||||
item = lookup[qid]
|
||||
|
@ -51,7 +51,7 @@ def from_name(name):
|
|||
label = wikibase.get_entity_label(entity)
|
||||
if label:
|
||||
i['label'] = label
|
||||
if 'en' in entity['descriptions']:
|
||||
if 'en' in entity.get('descriptions', {}):
|
||||
i['description'] = entity['descriptions']['en']['value']
|
||||
found.append(i)
|
||||
found.sort(key=lambda i: i.get('label', ''))
|
||||
|
|
|
@ -24,6 +24,16 @@ def api_call(params, api_url=wikidata_url):
|
|||
r = requests.get(api_url, params=call_params, timeout=5)
|
||||
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):
|
||||
r = api_call({'action': 'query', 'list': list_name, **params})
|
||||
return r.json()['query'][list_name]
|
||||
|
|
|
@ -153,12 +153,15 @@ def check_catalog(entity, catalog):
|
|||
catalog.update(cat)
|
||||
return
|
||||
|
||||
html = get_catalog_url(catalog_url)
|
||||
if html:
|
||||
description = get_description_from_page(html)
|
||||
if description:
|
||||
catalog['description'] = description
|
||||
return
|
||||
try:
|
||||
html = get_catalog_url(catalog_url)
|
||||
if html:
|
||||
description = get_description_from_page(html)
|
||||
if description:
|
||||
catalog['description'] = description
|
||||
return
|
||||
except UnicodeDecodeError:
|
||||
return
|
||||
|
||||
for property_id in sorted(catalog_ids):
|
||||
if property_id == 'P350':
|
||||
|
@ -203,7 +206,8 @@ def get_catalog_from_artwork(entity):
|
|||
check_catalog(entity, catalog)
|
||||
except (requests.exceptions.ReadTimeout,
|
||||
requests.exceptions.ConnectTimeout,
|
||||
requests.exceptions.ConnectionError):
|
||||
requests.exceptions.ConnectionError,
|
||||
requests.exceptions.TooManyRedirects):
|
||||
pass
|
||||
|
||||
return catalog
|
||||
|
|
Loading…
Reference in a new issue