Two quick SquareSpace tricks

In the process of migrating modulus to squarespace and starting a separate personal blog, I've come across two useful tricks that I wanted to share in case anyone else ever needs them.

The first is related to migrating from Drupal to SquareSpace. SquareSpace accepts a variety of formats, and they seem pretty ecited about their Moveable Type importer. I lucked out and found a script to export a drupal site to moveable type (scroll down for the python version), but unfortunately it didn't

  1. handle my node revisions correctly
  2. filter out unpublished comments
  3. write the date in a format that SquareSpace could handle
  4. have an obvious way for non-programmers to run it

So, I hacked in fixes to those four issues, and it worked like a charm. I tested it against drupal 5 -- no promises it'll actually work for you, but it was nice to have to work with.


def read_drupal(outfile,db,host,user,passwd):
import re,MySQLdb,time,wikimarkup
linefeed = re.compile('\r')
fout = open(outfile,'w')
db = MySQLdb.Connect(db = db,host = host, user = user, passwd = passwd)
c = db.cursor()
c2 = db.cursor()
cdata = db.cursor()
c.execute("SELECT nid,uid,type,title,status,created,comment from node where type = 'blog' AND status = 1")
stat = ["draft","publish"]
for (nid,uid,type,title,status,created,ncomment) in iter(c.fetchone,None):
#for i in range(0,10):
#(nid,uid,type,title,status,created,ncomment,teaser,body) = c.fetchone()
cdata.execute("SELECT body,teaser,format FROM node_revisions WHERE nid = %i ORDER BY timestamp" % int(nid))
(body, teaser,format) = cdata.fetchone()
# teaser = ''
# body = ''
body = linefeed.sub('',body)
if format==4:
body = wikimarkup.parse(body)
created = time.strftime('%m/%d/%Y %I:%M:%S %p',time.localtime(created))
c2.execute("SELECT name from users where uid = %s", (uid,))
(name,) = c2.fetchone()
fout.write("AUTHOR: %s\nTITLE: %s\nSTATUS: %s\nALLOW COMMENTS: %s\nCONVERT BREAKS: 1\nALLOW PINGS: %s\nDATE: %s\n" % (name,title,stat[status],ncomment,1,created))
c2.execute("SELECT name from term_node n, term_data d where n.nid = %s and n.tid = d.tid" % (nid,))
categories = [cat[0] for cat in iter(c2.fetchone,None)]
fout.write("TAGS:%s\n-----\n" % (','.join(categories)))
fout.write("BODY:\n%s\n-----\nKEYWORDS:\n/node/%s\n-----\n" % (body,nid))
if teaser != '':
fout.write("EXCERPT:\n%s\n-----\n" % (teaser,))
c2.execute("SELECT subject,comment,hostname,timestamp,name,mail,homepage from comments where status = 0 AND nid = %s order by cid" % (nid,))
for (subject,comment,hostname,timestamp,name,mail,homepage) in iter(c2.fetchone,None):
timestamp = time.strftime('%m/%d/%Y %I:%M:%S %p',time.localtime(timestamp))
#timestamp = time.strftime('%Y-%m-%dT%H:%M',time.localtime(timestamp))
fout.write( "COMMENT:\n")
if name != '':
fout.write( "AUTHOR: %s\n" % (name,))
if mail != '':
fout.write( "EMAIL: %s\n" % (mail,))
if hostname != '':
fout.write( "IP: %s\n" % (hostname,))
if homepage != '':
fout.write( "URL: %s\n" % (homepage,))
if timestamp != '':
fout.write( "DATE: %s\n" % (timestamp,))
fout.write( "%s\n" % (subject,));
fout.write(comment + "\n")
fout.write( "-----\n")

if __name__ == "__main__":
read_drupal("filename", "tablename", "server", "user", "password")


The second is a bit of javascript for creating a music player on blog enclosures. I'm posting about a minute of music, about every day, to my personal blog, and I'd wanted an easy way for people to be able to play it. So, I found a nice, creative-commons licensed music player called dewplayer, and wrote some jQuery code to find MP3 enclosured and add a player for them to the entry.


$(function () {
mp3s = $(".enclosureWrapper a[href$=mp3]");
mp3s.wrap("<div class='player-wrapper'></div>");
mp3s.each(function() {
elem = $(this);
wrapper = elem.parent();
song = elem.attr("href");
playerHolder = $("<div class='player'></div>");
swf: '/storage/resources/dewplayer.swf',
flashvars: {
mp3: song,
wmode: "transparent",
showtime: 1
params: {
wmode: "transparent"
height: 20,
width: 200


Because SquareSpace uses YUI internally, eventually I'll rewrite that code to just use YUI and swfObject. But, for now, it works and isn't too heavy, and has the advantage of only taking about 15 minutes to throw together.