X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/0da29a22a23a90561df3d201a299f3007c84d524..4e4277b12a41673d67f608609776f34adc9171e2:/apps/cover/views.py?ds=inline diff --git a/apps/cover/views.py b/apps/cover/views.py index 29fd117a..19d81c22 100644 --- a/apps/cover/views.py +++ b/apps/cover/views.py @@ -64,3 +64,34 @@ def preview_from_xml(request): image = cover.image().resize(PREVIEW_SIZE, Image.ANTIALIAS) image.save(os.path.join(settings.MEDIA_ROOT, fname)) return HttpResponse(os.path.join(settings.MEDIA_URL, fname)) + + +def flickr(request): + url = request.POST.get('flickr_url') + if url: + import re + from urllib2 import urlopen + + html = urlopen(url).read() + match = re.search(r'Some rights reserved', html) + if match: + license_url = match.group(1) + + re_license = re.compile(r'http://creativecommons.org/licenses/([^/]*)/([^/]*)/.*') + m = re_license.match(license_url) + if m: + license_name = 'CC %s %s' % (m.group(1).upper(), m.group(2)) + + m = re.search(r'By ([^<]*)', html) + if m: + author = m.group(1) + + url_size = url.rstrip('/') + '/sizes/o/' + html = urlopen(url_size).read() + m = re.search(r'
\s*