Skip to content

Instantly share code, notes, and snippets.

@monperrus
Created July 11, 2012 08:16
Show Gist options
  • Save monperrus/3088907 to your computer and use it in GitHub Desktop.
Save monperrus/3088907 to your computer and use it in GitHub Desktop.
Migrates the XML export file of js-kit/echo to the format of jskomment (http://code.google.com/p/jskomment/)
"""
Migrates the XML export file of js-kit/echo to the format of jskomment (http://code.google.com/p/jskomment/)
--Martin Monperrus
Tuesday, July 10 2012
"""
import xml.dom.minidom
import hashlib
import base64
import json
datasource = open('monperrus.net-comments.xml')
dom = xml.dom.minidom.parse(datasource)
for x in dom.getElementsByTagName('channel'):
title = x.getElementsByTagName('link')[0].firstChild.nodeValue
print 'Migrating comments of ',title
comments = []
for item in x.getElementsByTagName('item'):
comment = {}
comment['title']=title
comment['comment']=item.getElementsByTagName('description')[0].firstChild.nodeValue
comment['ctime']=item.getElementsByTagName('pubDate')[0].firstChild.nodeValue
try:# there may be no author data
comment['name']=item.getElementsByTagName('author')[0].firstChild.nodeValue
except: pass
tjson = json.dumps(comment)
comments.append(tjson)
comments.reverse()
commentfile = open('jskomment-data/'+hashlib.sha1(title).hexdigest(),'w')
for tjson in comments: commentfile.write(tjson+"\n")
commentfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment