Last active
January 4, 2016 08:49
-
-
Save mperlet/8598202 to your computer and use it in GitHub Desktop.
Python-Script that downloads all public flickr-photos from a user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyquery import PyQuery as pq | |
import sys, os, re, unicodedata | |
def slugify(value): | |
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') | |
value = re.sub('[^\w\s-]', '', value).strip().lower() | |
return re.sub('[-\s]+', '-', value) | |
url = u'http://www.flickr.com/photos/' | |
if len(sys.argv) == 1: | |
print(u'Username not found, run "python ficr.py <username> <size>"') | |
print(u'Sizes: o->Original, q->150x150, k->2048x???') | |
exit(1) | |
else: | |
username = sys.argv[1] | |
try: | |
size = sys.argv[2] | |
except: | |
size = u'o' | |
doc = pq(url='%s%s' % (url, username)) | |
for d in doc('.photo-display-item'): | |
doc = pq(url='%s/%s/%s/sizes/%s/' % (url,username,d.attrib['data-photo-id'],size)) | |
photo_title = u'%s' % doc('meta[name=title]').attr("content") | |
link = doc('#allsizes-photo').children().attr('src') | |
print photo_title | |
print link | |
os.system(u'wget -O "%s.jpg" %s &' % (slugify(photo_title), link)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip install pyQuery
python fickr.py <username> <size>
e.g.python ficr.py mperlet k