Created
June 14, 2013 06:03
-
-
Save kennethreitz/5779780 to your computer and use it in GitHub Desktop.
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
import os | |
import requests | |
from clint.textui import progress | |
s = requests.session() | |
def iter_photos(): | |
r = requests.get('http://blackbox.kennethreitz.org/records/?q=metadata.service:flickr&sort=epoch:asc&size=10000') | |
for record in r.json['records']: | |
yield record | |
def iter_urls(): | |
for photo in iter_photos(): | |
yield photo['links']['src'] | |
def iter_download(): | |
for url in progress.bar([f for f in iter_urls()]): | |
name = url.split('/')[-1] | |
if not os.path.exists(name): | |
try: | |
r = s.get(url) | |
with open(name, 'w') as f: | |
f.write(r.content) | |
except Exception: | |
pass | |
with open('badphotos') as f: | |
bad_files = f.read().split() | |
photos = [p for p in iter_photos()] | |
# urls = [p['links']['src'] for p in photos] | |
for bad_file in bad_files: | |
print bad_file | |
for photo in photos: | |
if bad_file in photo['links']['src']: | |
print 'found!' | |
name = photo['links']['path:data'].split('/')[-1] | |
r = s.get(photo['links']['path:data']) | |
with open(bad_file, 'w') as f: | |
f.write(r.content) | |
# [j for j in iter_download()] |
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
import os | |
import requests | |
from clint.textui import progress | |
s = requests.session() | |
def iter_photos(): | |
r = requests.get('http://blackbox.kennethreitz.org/records/?q=metadata.service:flickr&sort=epoch:asc&size=10000') | |
for record in r.json['records']: | |
yield record | |
def iter_urls(): | |
for photo in iter_photos(): | |
yield photo['links']['src'] | |
def iter_download(): | |
for url in progress.bar([f for f in iter_urls()]): | |
name = url.split('/')[-1] | |
if not os.path.exists(name): | |
try: | |
r = s.get(url) | |
with open(name, 'w') as f: | |
f.write(r.content) | |
except Exception, e: | |
pass | |
[j for j in iter_download()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment