Two quick SquareSpace tricks
Sunday, February 1, 2009 at 9:08PM 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
- handle my node revisions correctly
- filter out unpublished comments
- write the date in a format that SquareSpace could handle
- 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")
fout.write('''--------\n''')
fout.close()
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>");
wrapper.prepend(playerHolder);
playerHolder.flash({
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.

Reader Comments (13)
any way you can help me out by showing me how to implement this on my page? Copy and pasting it to the html doesnt work, so i must be missing something? Can you follow up with more details please? Itll be so helpful if u can help make this work...
thanks
im talking bout the Dewplayer
Thanks for the movable type export code. I'm new to Python - do you have the original indented version I can try? I'm at:
--
Matthew Cornell | matt@matthewcornell.org | 413-626-3621 | 34 Dickinson Street, Amherst MA 01002 | matthewcornell.org
@mike, you'll need to have jQuery also in your page -- I just added a reference to it in the HTML injection part of my settings.
Hey Matt, is there any chance I could get the indented version of that file also? I can't seem figure out where they should go.
Thanks,
Joe
thanks a million, the trick works perfectly
The blog is in reality the great on this worthy subject. I match in together with your conclusions and looking forward to your coming updates. Just saying thanks will not just be enough, for the fantastic clarity inside your writing. I put a link to your blog at my site, hope you don't mind?
Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
Great tricks. Well done as they were very useful to find.
Each & every tips of your post are awesome.
As a famous Paris Fashion brand, Herve Leger Strapless is taking great effort to show women`s perfect figures and gentle charactors. 2010 new style Herve Leger help women to show this line of beauty perfectly. This is also the tenet of Herve Leger Strapless .Originating in France,2010 new style Herve Leger also have the charactor as Paris Women does, natural but not fake, romantic, elegant and Vogue .In the 1980s, Moncler Polo Shirt become unprecedentedly popular all over the world. They are poplular because all the
Moncler Jackets Vest are made of high- quality down.So many young people are fascinated with Moncler Polo Shirt , and we guess you must be one of them. Start to be the trend-spotter from owning an Moncler Accessories.The red outsole is the distinctive features of Christian Louboutin Boots , also is the female of gentle, lovely, beautiful and sexy logo.Soon, the red high-heeled Christian Louboutin Flats spread all over the world after Cinderella's fairy tales, especially the big stars and royal aristocrats let
Christian Louboutin Flats appear in the front of the world. Christian Louboutin Boots favor gorgeous colors with various exotic. . No matter what kinds of HERMES PURSE you like, you can have a look at HERMES BELT .Please go and check out, you will be attracted by those beautiful and elegant belt. And among the various Hermes Kelly , there must be one suitable for you.Hermes Lindy&Hermes Evelyne one of the best handbag brands in the world.
регистрация сайта
сайт