fix tests and importers
[redakcja.git] / src / cover / utils.py
index 6815d29..59e194f 100644 (file)
@@ -62,7 +62,7 @@ def get_flickr_data(url):
     m = re.search(r'modelExport: (\{.*\})', html)
     try:
         assert m
     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 {
     except (AssertionError, ValueError, IndexError, KeyError):
         raise FlickrError('Error reading image URL.')
     return {
@@ -96,6 +96,9 @@ def get_wikimedia_data(url):
     if wikidata_match is not None:
         qitem = wikidata_match.group(1)
         client = Client()
     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))
         entity = client.get(qitem)
         meta['title'] = entity.label.get('pl', str(entity.label))
         author = entity.get(client.get(WIKIDATA.CREATOR))