# Greg Hewgill <greg@hewgill.com> http://hewgill.com
# Version 1.3.2
#
-# $Id$
-#
-# This program reads the journal entries from a livejournal (or compatible)
-# blog site and archives them in a subdirectory named after the journal name.
-#
-# The configuration is read from "ljdump.config". A sample configuration is
-# provided in "ljdump.config.sample", which should be copied and then edited.
-# The configuration settings are:
-#
-# server - The XMLRPC server URL. This should only need to be changed
-# if you are dumping a journal that is livejournal-compatible
-# but is not livejournal itself.
-#
-# username - The livejournal user name. A subdirectory will be created
-# with this same name to store the journal entries.
-#
-# password - The account password. This password is never sent in the
-# clear; the livejournal "challenge" password mechanism is used.
-#
-# 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
if isinstance(e[k], {}.__class__):
dumpelement(f, k, e[k])
else:
- s = unicode(str(e[k]), "UTF-8")
+ try:
+ s = unicode(str(e[k]), "UTF-8")
+ except UnicodeDecodeError:
+ # fall back to Latin-1 for old entries that aren't UTF-8
+ s = unicode(str(e[k]), "cp1252")
f.write("<%s>%s</%s>\n" % (k, saxutils.escape(s), k))
f.write("</%s>\n" % name)
print "%d errors" % errors
if __name__ == "__main__":
- config = xml.dom.minidom.parse("ljdump.config")
- server = config.documentElement.getElementsByTagName("server")[0].childNodes[0].data
- username = config.documentElement.getElementsByTagName("username")[0].childNodes[0].data
- password = config.documentElement.getElementsByTagName("password")[0].childNodes[0].data
+ if os.access("ljdump.config", os.F_OK):
+ config = xml.dom.minidom.parse("ljdump.config")
+ server = config.documentElement.getElementsByTagName("server")[0].childNodes[0].data
+ username = config.documentElement.getElementsByTagName("username")[0].childNodes[0].data
+ password = config.documentElement.getElementsByTagName("password")[0].childNodes[0].data
+ else:
+ from getpass import getpass
+ print "ljdump - livejournal archiver"
+ print
+ print "Enter your Livejournal username and password."
+ print
+ server = "http://livejournal.com"
+ username = raw_input("Username: ")
+ password = getpass("Password: ")
+ print
ljdump(server, username, password)