Skip to content

Commit

Permalink
Merge pull request #1 from kid-a/master
Browse files Browse the repository at this point in the history
Pull review
  • Loading branch information
friedcell committed Jun 4, 2012
2 parents b037c3a + fcea8f9 commit b109bd8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions picplzexport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys, os, urllib, urllib2, json, time, getpass
import sys, os, urllib, urllib2, json, time, getpass, re

try:
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -59,7 +59,12 @@ def get_photos(username, password):
print "Logging in & fetching first photos..."
res = make_request("/login/?next=/yourphotos/", {"email": username, "password": password, "csrfmiddlewaretoken": csrf})
html = res.read()
last_id = html.split("\"last_id\":")[1].split("}")[0]

try: last_id = html.split("\"last_id\":")[1].split("}")[0]
except:
print "Wrong username/password combination. Aborting."
sys.exit(0)

extract_photos(html)
if last_id:
get_more_photos(last_id)
Expand Down Expand Up @@ -137,7 +142,7 @@ def download_file(url, filename):
f.close()

def build_html(username):
global phtoos
global photos
imagelist = []
for p in photos:
imagelist.append('<li id="i%(id)s"><h2>%(title)s</h2><img src="%(filename)s" /></li>' % p)
Expand All @@ -157,7 +162,7 @@ def build_html(username):
username = re.sub('[-\s]+', '-', re.sub('[^\w\s-]', '', username.split("@")[0]).strip().lower())
filename = "picplz_%s_backup.html" % username
f = open(filename, 'w')
f.write(h)
f.write(h.encode('utf-8'))
f.close()
print "HTML built:", filename

Expand Down

0 comments on commit b109bd8

Please sign in to comment.