Created
December 20, 2013 16:17
-
-
Save anmsid/8057156 to your computer and use it in GitHub Desktop.
A simple script to convert feedly.cache (json) file to opml that can be imported back to feedly.
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
#!/usr/bin/env python | |
""" | |
A simple script to convert feedly.cache (json) file to opml. | |
Usage: python feedly2opml.py feedly.cache | |
It will print the opml to stdout. Use redirection to save into file: | |
python feedly2opml.py feedly.cache > feedly.opml | |
Author: anmsid[at]gmail.com | |
""" | |
import re | |
import sys | |
from xml.sax.saxutils import escape | |
OPML_HEADER = """<?xml version="1.0" encoding="UTF-8"?> | |
<opml version="1.0"> | |
<head> | |
<title>Feedly OPML</title> | |
</head> | |
<body> | |
""" | |
OPML_FOOTER = """ | |
</body> | |
</opml> | |
""" | |
if __name__ == '__main__': | |
try: | |
feedly = open(sys.argv[1]).read() | |
except: | |
sys.exit("Usage: python feedly2opml.py feedly.cache"); | |
p = re.compile(r'{"title":"(.+?)","website":"(.+?)","feedId":"feed/(.+?)"', re.M|re.S) | |
m = p.findall(feedly) | |
if len(m) > 0: | |
print OPML_HEADER | |
for title, website, feed in m: | |
print '\t\t<outline text="%s" htmlUrl="%s" type="rss" xmlUrl="%s" />' %(escape(title), escape(website), escape(feed)) | |
print OPML_FOOTER | |
else: | |
print "Can not extract feed data from file, make sure the file is not corrupt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment