+
+
+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'<a href="([^"]*)" rel="license cc:license">Some rights reserved</a>', html)
+ try:
+ assert match
+ license_url = match.group(1)
+ re_license = re.compile(r'http://creativecommons.org/licenses/([^/]*)/([^/]*)/.*')
+ m = re_license.match(license_url)
+ assert m
+ license_name = 'CC %s %s' % (m.group(1).upper(), m.group(2))
+ except AssertionError:
+ license_name = 'NIEZNANA LICENCJA'
+
+ m = re.search(r'<strong class="username">By <a href="[^"]*">([^<]*)</a></strong>', html)
+ if m:
+ author = m.group(1)
+ else:
+ author = "NIEZNANY AUTOR"
+
+ url_size = url.rstrip('/') + '/sizes/o/'
+ html = urlopen(url_size).read()
+ m = re.search(r'<div id="allsizes-photo">\s*<img src="([^"]*)"', html)
+ if m:
+ image_url = m.group(1)
+ else:
+ url = ""
+
+ return render(request, 'cover/flickr.html', locals())