Created
July 11, 2012 08:16
-
-
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/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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