#!/usr/bin/python2.2 """ pydelicious - A simple script to generate a textile formatted pyblosxom entry for one day's links on del.icio.us Documentation: Author: Jim Hughes, License: GPL """ import time import urllib2 import xmltramp basedir = '/home/jim/blog/linkblog' # format yesterday's date in 2005-12-31 style date = time.strftime("%Y-%m-%d", time.gmtime(time.time() - 24*60*60)) not_testing = 1 if not_testing: # Set up authentication info. authinfo = urllib2.HTTPBasicAuthHandler() authinfo.add_password('del.icio.us API', 'https://api.del.icio.us', 'jimh', 'password') opener = urllib2.build_opener(authinfo) opener.addheaders = [('User-Agent', 'pydelicious/1.0 +http://feetup.org/blog/dev/projects.html')] urllib2.install_opener(opener) data = urllib2.urlopen('https://api.del.icio.us/v1/posts/get?dt=%s' % date).read() else: # Dummy data for testing data = """ """ posts = xmltramp.parse(data) if len(posts): f = open('%s/links_%s.txtl' % (basedir, date), 'w') # Title for Pyblosxom. f.write('%s links\n\n' % date) # This is a list formatted for Textile. for post in posts: if post._attrs.has_key('extended'): f.write('* "%s(%s)":%s\n' % (post('description'), post('extended'), post('href'))) else: f.write('* "%s":%s\n' % (post('description'), post('href'))) taglist = post('tag').split() tagurls = '** Tags' for tag in taglist: tagurls += ' "%s":http://del.icio.us/tag/%s' % (tag, tag) f.write( tagurls ) f.write('\n') # if others have tagged this post, link to them if post._attrs.has_key('others') and post('others') != '1': f.write('** "Others linking to this item":http://del.icio.us/url/%s\n' % post('hash')) f.write("""\nTaken from "Jim's del.icio.us links":http://del.icio.us/jimh\n""") f.close()