-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebshots.py
89 lines (60 loc) · 2.32 KB
/
webshots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Webshots grabber
"Login, list and download all photos at fullsize into folders with album name"
import os
import sys
import time
import urllib
import httplib2
import getAlbums
import getPhotos
import getFullSizePhoto
#
# Place your Username and password here before running
#
if len(sys.argv) != 3:
print "Usage: webshots.py <username> <password>"
sys.exit(0)
user = sys.argv[1]
password = sys.argv[2]
# Authenticate login.
url = 'http://www.webshots.com/login'
body = { 'done':'http%3A%2F%2Fwww.webshots.com%2Fhomepage.html', 'username': user, 'password': password, 'I1.x':'0', 'I1.y':'0', 'I1':'Login' }
headers = {'Content-type': 'application/x-www-form-urlencoded'}
print "Accessing " + user + "'s photos..."
http = httplib2.Http()
response, content = http.request(url,'POST', headers=headers, body=urllib.urlencode(body))
headers['Cookie'] = response['set-cookie']
print "Obtaining albums..."
albums = getAlbums.getAlbumsFromUser( user, http, headers )
if len( albums ) > 0 :
print str( len( albums ) ) + " albums found."
rootPath = "webshots"
if os.path.exists( rootPath ) == False:
os.mkdir( rootPath )
photolist = ""
for albumUrl in albums:
albumName, photos = getPhotos.getPhotosFromAlbum( albumUrl, http, headers )
print albumName + " : " + str( len( photos ) ) + " photos (or videos)"
albumPath = rootPath + "/" + albumName
if os.path.exists( albumPath ) == False:
os.mkdir( albumPath )
for photoName, photoUrl in photos.iteritems():
photoFullUrl = getFullSizePhoto.getFullSizePhotoFromPhotoPage( photoUrl, http, headers )
if photoFullUrl != "" :
photoFileOutput = albumPath + "/" + photoName + ".jpg"
if os.path.exists( photoFileOutput ) == False:
print " Retrieving " + photoName
response, image = http.request( photoFullUrl, 'GET', headers=headers )
fopen = open( photoFileOutput, "wb" )
fopen.write( image )
fopen.close();
photolist += albumName + " " + photoName + " " + photoFullUrl + "\n"
time.sleep(3) # sleep so we don't hit webshots to often (this is 3 seconds, 100 photos will take *at least* 5 minutes)
#break # Just get the one for testing
time.sleep(1)
#break
fopen = open( rootPath + "/photolist.txt", "a" )
fopen.write( photolist )
fopen.close()
else:
print "No albums found, were your username and password correct?"