Created
December 29, 2009 08:22
-
-
Save jackysee/265214 to your computer and use it in GitHub Desktop.
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
/** | |
Convert from Google Reader API's ATOM to RSS2.0 | |
It seems that the Google Reader API's ATOM cannot be read by Wordpress import properly. So Write a script to convert it to a simple RSS2.0 format. | |
Still many trade off: 1) may not be full feed. 2) may not be full archive 3) Images still on remote server. 4) No comments retrieved. | |
You need to install groovy http://groovy.codehaus.org/ to run the script | |
1. Get a copy of your RSS archive from Google Reader e.g. http://www.google.com/reader/atom/feed/http://feeds.feedburner.com/Room2046?r=n&n=1500 | |
2. save the name as input.xml | |
3. run the script in the same directory | |
4. the output is at output.xml | |
*/ | |
Locale.setDefault(Locale.ENGLISH) | |
def root = new XmlParser().parse("input.xml") | |
def osw = new OutputStreamWriter(new FileOutputStream("out.xml"),'utf-8') | |
def xml = new groovy.xml.MarkupBuilder(osw) | |
xml.rss(version:"2.0", "xmlns:content":"http://purl.org/rss/1.0/modules/content/"){ | |
channel(){ | |
title(root.title.text()) | |
link(root.link[1].'@href') | |
langauge("zh-HK") | |
root.entry.each{en-> | |
def cat = en.category.findAll{it.@scheme != 'http://www.google.com/reader/'}[0]?.'@term' | |
def t = en.title.text() | |
def l = en.link.'@href'[0] | |
def s = en.summary.text() | |
def c = en.content.text() | |
def pd = Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", en.published.text()) | |
def ld = Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", en.updated.text()) | |
def a = en.author.name.text() | |
item(){ | |
category(''){osw.write("<![CDATA[${cat}]]>")} | |
title(t) | |
link(l) | |
description(s) | |
'content:encoded'(''){osw.write("<![CDATA[${c?c:s}]]>")} | |
pubDate(pd.format("EEE, dd MMMM yyyy HH:mm:ss z")) //Sat, 07 Sep 2002 00:00:01 GMT | |
lastBuildDate(ld.format("EEE, dd MMMM yyyy HH:mm:ss z")) | |
author(a) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment