X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/81f5e7445d649ead05b4d3d0a15b742444cd8b06..77538c1274e0e67ddab55e68099df94bc127c0e0:/src/cover/utils.py diff --git a/src/cover/utils.py b/src/cover/utils.py index 56fb24a7..59e194ff 100644 --- a/src/cover/utils.py +++ b/src/cover/utils.py @@ -62,7 +62,7 @@ def get_flickr_data(url): m = re.search(r'modelExport: (\{.*\})', html) try: assert m - download_url = 'https:' + json.loads(m.group(1))['main']['photo-models'][0]['sizes']['o']['url'] + download_url = 'https:' + json.loads(m.group(1))['main']['photo-models'][0]['data']['sizes']['data']['o']['data']['url'] except (AssertionError, ValueError, IndexError, KeyError): raise FlickrError('Error reading image URL.') return { @@ -96,10 +96,16 @@ def get_wikimedia_data(url): if wikidata_match is not None: qitem = wikidata_match.group(1) client = Client() + client.opener.addheaders = [( + 'User-Agent', 'Wolne Lektury Redakcja / Python-wikidata' + )] entity = client.get(qitem) meta['title'] = entity.label.get('pl', str(entity.label)) author = entity.get(client.get(WIKIDATA.CREATOR)) - meta['author'] = author.label.get('pl', str(author.label)) + if author is not None: + meta['author'] = author.label.get('pl', str(author.label)) + else: + meta['author'] = '' if meta['license_name'] == 'Public domain': meta['license_name'] = 'domena publiczna'