Created
March 13, 2011 20:54
-
-
Save gauteh/868431 to your computer and use it in GitHub Desktop.
Extract full-sized photos from photos.live.com using rss feed
This file contains hidden or 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
#! /usr/bin/python2 | |
# | |
# Gaute Hope <[email protected]> 2011 | |
# | |
# Extract full-size photos from photos.live.com using rss feed | |
# | |
# Requires: - feedparser: http://feedparser.org/ - Python 2 | |
VERSION = 1 | |
print "photosliveextract - v", VERSION | |
feeduri = '' | |
outdir = 'extracted/' | |
import os | |
import sys | |
import time | |
if not os.path.exists (outdir): | |
os.makedirs (outdir) | |
import feedparser | |
import urllib | |
# load feed | |
sys.stdout.write ('loading feed..: ' + feeduri) | |
sys.stdout.flush () | |
feed = feedparser.parse (feeduri) | |
sys.stdout.write (' - done.\n') | |
items = feed.items()[9][1] | |
offset = 0 # 0 indexed [in case you don't want to start at the first | |
# photo] | |
index = offset | |
items = items[offset:] | |
failed = 0 | |
print "Downloading:", len(items), "items." | |
for i in items: | |
tries = 50 | |
while tries: | |
try: | |
sys.stdout.write ('[' + str(index) + "/" + str(len(items)) + '] downloading: ' + i['title'] + '..') | |
sys.stdout.flush () | |
# get page | |
p = urllib.urlopen (i['link']).read () | |
start = p.find ('<a id="spPreviewLink" href="') | |
end = p.find ('" rel="nofollow"', start) | |
photouri = p[start+28:end].replace(':',':').replace('?','?').replace('=','=') | |
sys.stdout.write (': ' + photouri + ' ..') | |
sys.stdout.flush () | |
# get photo | |
urllib.urlretrieve (photouri, os.path.join (outdir, i['title'])) | |
sys.stdout.write ('done.\n') | |
urllib.urlcleanup () | |
tries = 0 | |
except: | |
if (tries == 0): | |
print "[" + str(index) + "] FAILED:", i['title'] | |
failed = failed + 1 | |
else: | |
sys.stdout.write ('failed, retrying: ' + str(tries) + ' in 5 secs\n') | |
tries = tries - 1 | |
time.sleep(5) | |
index = index + 1 | |
print "Finished, completed:", (index - offset), "failed:", failed, "of total:", len(items) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment