fix tests and importers
[redakcja.git] / src / cover / utils.py
index 56fb24a..59e194f 100644 (file)
@@ -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'