]> wagner.pp.ru Git - oss/ljdump.git/commitdiff
download and save userpic images
authorGreg Hewgill <greg@hewgill.com>
Thu, 8 Jan 2009 10:46:33 +0000 (23:46 +1300)
committerGreg Hewgill <greg@hewgill.com>
Thu, 8 Jan 2009 10:46:33 +0000 (23:46 +1300)
ChangeLog
ljdump.py

index 9e05c7412ec50af157544a90de80a5033aeb09b9..183f4afea288c6abcbd80f1c0b63548668c1eb83 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ ChangeLog - ljdump
 Version 1.3.1 - 2009-01-08
 
 - Handle userpic keywords with non-ASCII characters
+- Download and save userpic images
 
 Version 1.2 - 2006-09-08
 
index e2114b33b86dbd9234c3719f9962c4eb75324acd..e7534a91b83f940f69321a0142c743069eb2adb0 100755 (executable)
--- a/ljdump.py
+++ b/ljdump.py
 #
 # Copyright (c) 2005-2006 Greg Hewgill
 
-import codecs, md5, os, pickle, pprint, re, sys, urllib2, xml.dom.minidom, xmlrpclib
+import codecs, md5, os, pickle, pprint, re, shutil, sys, urllib2, xml.dom.minidom, xmlrpclib
 from xml.sax import saxutils
 
+MimeExtensions = {
+    "image/gif": ".gif",
+    "image/jpeg": ".jpg",
+    "image/png": ".png",
+}
+
 def calcchallenge(challenge, password):
     return md5.new(challenge+md5.new(password).hexdigest()).hexdigest()
 
@@ -256,11 +262,18 @@ f = open("%s/user.map" % Username, "w")
 pickle.dump(usermap, f)
 f.close()
 
+print "Fetching userpics for: %s" % Username
 f = open("%s/userpics.xml" % Username, "w")
 print >>f, """<?xml version="1.0"?>"""
 print >>f, "<userpics>"
 for p in userpics:
     print >>f, """<userpic keyword="%s" url="%s" />""" % (p, userpics[p])
+    pic = urllib2.urlopen(userpics[p])
+    ext = MimeExtensions.get(pic.info()["Content-Type"], "")
+    picf = open("%s/%s%s" % (Username, codecs.utf_8_decode(p)[0], ext), "wb")
+    shutil.copyfileobj(pic, picf)
+    pic.close()
+    picf.close()
 print >>f, "</userpics>"
 f.close()