#!/usr/bin/python # get all entries from advogato for a specific user import os import sys import xmlrpclib import datetime if len (sys.argv) < 2: sys.stderr.write("Please specify a user name to get entries for\n") sys.exit (1) username = sys.argv[1] server = xmlrpclib.Server("http://www.advogato.org/XMLRPC") if server.test.sumprod(5,7) != [12, 35]: sys.stderr.write("Could not properly connect to advogato XML RPC server\n") sys.exit (1) length = server.diary.len (username) print "Number of entries for %s: %d" % (username, length) if os.system('mkdir %s' % username) != 0: sys.stderr.write("Could not create directory %s\n" % username) sys.exit (1) for i in range(length): print "Getting entry %d" % i created, updated = server.diary.getDates(username, i) #Convert the iso-format text representation to a python DateTime object. #There's an RFC about adding a conversion for this to python itself. #I have no idea whether this is how you should get substrings in python. I hope not. murrayc. datestring = "%s" % created; yearstring = "%s" % datestring[0:4] monthstring = "%s" % datestring[4:6] daystring = "%s" % datestring[6:8] #Then there's a "T" to divide the date from the time. hourstring = "%s" % datestring[9:11] #Then there's a ":" minutesstring = "%s" % datestring[12:14] #Then there's a ":" secondsstring = "%s" % datestring[15:16] #timestring = "%s" % thedatetime = datetime.datetime( int(yearstring), int(monthstring), int(daystring), int(hourstring), int(minutesstring), int(secondsstring)) #Get a pyblosxom-format text representation of the date/time (does not use seconds): pyblosxom_datestring = "%02d-%02d-%02d-%02d-%02d" % (thedatetime.year, thedatetime.month, thedatetime.day, thedatetime.hour, thedatetime.minute) html = server.diary.get(username, i).encode('utf-8') #Pyblosxom seems to need .txt extensions - it does not recognise .html files: path = os.path.join(username, "%s.txt" % pyblosxom_datestring) open(path, 'w').write (html) print "Done."