Skip to content

Instantly share code, notes, and snippets.

@gauteh
Created March 13, 2011 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauteh/868431 to your computer and use it in GitHub Desktop.
Save gauteh/868431 to your computer and use it in GitHub Desktop.
Extract full-sized photos from photos.live.com using rss feed
#! /usr/bin/python2
#
# Gaute Hope <eg@gaute.vetsj.com> 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('&#58;',':').replace('&#63;','?').replace('&#61;','=')
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