X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/29d7fc838e192b6a18dd31d81fe9ab1bc37b6cbb..5709ad98f0e529a37e858931e1ec2f37c3875dcf:/apps/cover/management/commands/refresh_covers.py diff --git a/apps/cover/management/commands/refresh_covers.py b/apps/cover/management/commands/refresh_covers.py index 854f3bbe..2c78db9b 100644 --- a/apps/cover/management/commands/refresh_covers.py +++ b/apps/cover/management/commands/refresh_covers.py @@ -22,9 +22,10 @@ class Command(BaseCommand): from_id = options.get('from_id', 1) for image in Image.objects.filter(id__gte=from_id).exclude(book=None).order_by('id'): print image.id - if 'flickr.com' in image.source_url: + if image.source_url and 'flickr.com' in image.source_url: try: flickr_data = get_flickr_data(image.source_url) + print flickr_data except FlickrError as e: print 'Flickr analysis failed: %s' % e else: @@ -35,12 +36,12 @@ class Command(BaseCommand): print 'Download url already present in image %s' % same_url.get().id continue try: - t = URLOpener().open(image.download_url).read() + t = URLOpener().open(flickr_url).read() except urllib.URLError: print 'Broken download url' except IOError: print 'Connection failed' else: - image.download_url = flickr_data['download_url'] + image.download_url = flickr_url image.file.save(image.file.name, ContentFile(t)) image.save()