« Web writing for Communicators | Main | Starting back up »
Sunday
01Feb2009

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")
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 (7)

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

August 27, 2009 | Unregistered Commentermike

im talking bout the Dewplayer

August 27, 2009 | Unregistered Commentermike

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

September 20, 2009 | Unregistered CommenterMatthew Cornell

@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.

October 5, 2009 | Unregistered CommenterMatt Bowen

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

December 19, 2009 | Unregistered CommenterJoe

I visited this sight for the first time and I found it best but I would like to add that currently we are living in the era of IT but unfortunately more than half of world population is illiterate. Out of those a few are computer and internet familiar so the target market for internet marketing is niche. Therefore the developed nations should promote itil certification as well as computer literacy in these developing areas so the target market can be increased in future.

January 28, 2010 | Unregistered Commenterjames

Wonderful post... Very informational and educational as usual!

Acai Optimum

March 6, 2010 | Unregistered CommenterAcai Berry

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>