]> wagner.pp.ru Git - oss/ljdump.git/blobdiff - ljdump.py
handle path separators in userpic keywords
[oss/ljdump.git] / ljdump.py
index 0c9ec89e8483b1cd9d2ceb1e50c748101677d45d..d1e92874f7815e076548f24a8e93926bc9542f55 100755 (executable)
--- a/ljdump.py
+++ b/ljdump.py
@@ -2,7 +2,7 @@
 #
 # ljdump.py - livejournal archiver
 # Greg Hewgill <greg@hewgill.com> http://hewgill.com
-# Version 1.2
+# Version 1.3.1
 #
 # $Id$
 #
@@ -26,6 +26,9 @@
 # This program may be run as often as needed to bring the backup copy up
 # to date. Both new and updated items are downloaded.
 #
+# The community http://ljdump.livejournal.com has been set up for questions
+# or comments.
+#
 # LICENSE
 #
 # This software is provided 'as-is', without any express or implied
@@ -44,7 +47,7 @@
 #    misrepresented as being the original software.
 # 3. This notice may not be removed or altered from any source distribution.
 #
-# Copyright (c) 2005-2006 Greg Hewgill
+# Copyright (c) 2005-2009 Greg Hewgill
 
 import codecs, md5, os, pickle, pprint, re, shutil, sys, urllib2, xml.dom.minidom, xmlrpclib
 from xml.sax import saxutils
@@ -281,7 +284,14 @@ 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")
+    picfn = re.sub(r"[\/]", "_", p)
+    try:
+        picfn = codecs.utf_8_decode(picfn)[0]
+        picf = open("%s/%s%s" % (Username, picfn, ext), "wb")
+    except:
+        # for installations where the above utf_8_decode doesn't work
+        picfn = "".join([ord(x) < 128 and x or "?" for x in picfn])
+        picf = open("%s/%s%s" % (Username, picfn, ext), "wb")
     shutil.copyfileobj(pic, picf)
     pic.close()
     picf.close()