forked from jmrodri/sm-photo-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestupload.py
51 lines (43 loc) · 1.44 KB
/
testupload.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
import sys
import httplib
from xmlrpclib import *
import hashlib
if len(sys.argv) < 3:
print("testupload.py username password albumid")
sys.exit(1)
#albumid = 10116334
albumid = sys.argv[3]
filename = 'test.jpg'
client = ServerProxy("https://api.smugmug.com/services/api/xmlrpc/1.2.1/")
session = client.smugmug.login.withPassword(sys.argv[1], sys.argv[2], "4XHW8Aw7BQqbkGszuFciGZH4hMynnOxJ")
# read in image file
f = file(filename, "rb")
data = f.read()
f.close()
# prep HTTP PUT to upload image
#h = httplib.HTTP("upload.smugmug.com")
h = httplib.HTTPConnection("upload.smugmug.com")
h.connect()
h.putrequest('PUT', "/" + filename)
print("Content-Length: %s" % str(len(data)))
print("Content-MD5: %s" % hashlib.md5(data).hexdigest())
print("X-Smug-SessionID: %s" % session["Session"]["id"])
print("X-Smug-Version: 1.2.1")
print("X-Smug-ResponseType: XML-RPC")
print("X-Smug-AlbumID: %s" % str(albumid))
print("X-Smug-FileName: %s" % filename)
h.putheader('Content-Length', str(len(data)))
h.putheader('Content-MD5', hashlib.md5(data).hexdigest())
h.putheader('X-Smug-SessionID', session['Session']['id'])
h.putheader('X-Smug-Version', '1.2.1')
h.putheader('X-Smug-ResponseType', 'XML-RPC')
h.putheader('X-Smug-AlbumID', str(albumid))
h.putheader('X-Smug-FileName', filename)
h.endheaders()
h.send(data)
# response output
resp = h.getresponse()
print("%s: %s" % (resp.status, resp.reason))
result = resp.read()
h.close()
print("PUT: result: %s" % result)