Created
February 28, 2015 14:08
-
-
Save nfroidure/fd8143db0ae7b59805b7 to your computer and use it in GitHub Desktop.
Convert CSV to WXR comments format of Disqus (see https://help.disqus.com/customer/portal/articles/472150-custom-xml-import-format)
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
var CSV = require('oh-csv'); | |
process.stdout.write( | |
'<?xml version="1.0" encoding="UTF-8"?>' + '\r\n' + | |
'<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"' + '\r\n' + | |
' xmlns:dsq="http://www.disqus.com/" xmlns:dc="http://purl.org/dc/elements/1.1/"' + '\r\n' + | |
' xmlns:wp="http://wordpress.org/export/1.0/">' + '\r\n' + | |
' <channel>' + '\r\n' | |
); | |
var parser = new CSV.Parser({ | |
fields: [ | |
'href', 'title', 'postCreated', 'id', 'entry', 'author', 'email', 'website', 'content', 'created', | |
'lang' | |
], | |
sep: ',', | |
linesep: ['\n', '\r', '\r\n'], | |
quote: '"', | |
esc: '"' | |
}); | |
parser.on('data', function(row) { | |
process.stdout.write( | |
' <item>' + '\r\n' + | |
' <title>' + row.title + '</title>' + '\r\n' + | |
' <link>http://insertafter.com/' + row.lang + '/blog/' + row.href + '.html</link>' + '\r\n' + | |
' <content:encoded><![CDATA[]]></content:encoded>' + '\r\n' + | |
' <dsq:thread_identifier>' + row.entry + '</dsq:thread_identifier>' + '\r\n' + | |
' <wp:post_date_gmt>' + row.postCreated + '</wp:post_date_gmt>' + '\r\n' + | |
' <wp:comment_status>open</wp:comment_status>' + '\r\n' + | |
' <wp:comment>' + '\r\n' + | |
' <wp:comment_id>' + row.id + '</wp:comment_id>' + '\r\n' + | |
' <wp:comment_author>' + row.author + '</wp:comment_author>' + '\r\n' + | |
' <wp:comment_author_email>' + row.email + '</wp:comment_author_email>' + '\r\n' + | |
' <wp:comment_author_url>' + row.website + '</wp:comment_author_url>' + '\r\n' + | |
' <wp:comment_author_IP></wp:comment_author_IP>' + '\r\n' + | |
' <wp:comment_date_gmt>' + row.created + '</wp:comment_date_gmt>' + '\r\n' + | |
' <wp:comment_content><![CDATA[' + row.content + ']]></wp:comment_content>' + '\r\n' + | |
' <wp:comment_approved>1</wp:comment_approved>' + '\r\n' + | |
' <wp:comment_parent>0</wp:comment_parent>' + '\r\n' + | |
' </wp:comment>' + '\r\n' + | |
' </item>' + '\r\n' | |
); | |
}); | |
parser.on('end', function() { | |
process.stdout.write( | |
' </channel>' + '\r\n' + | |
'</rss>' + '\r\n' | |
); | |
}); | |
require('fs').createReadStream('./comments.csv').pipe(parser); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment