Created
March 14, 2013 16:57
-
-
Save vincebusam/5163032 to your computer and use it in GitHub Desktop.
Python script to upload your Google Reader subscriptions to selfoss.
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/python | |
# | |
# Takes a Google Reader subscriptions file, and adds them all (with tags) to selfoss | |
# First arg: xml file. Second arg: URL to selfoss installation | |
# | |
import sys | |
import urllib | |
import urllib2 | |
import xml.parsers.expat | |
tag = "" | |
# 3 handler functions | |
def start_element(name, attrs): | |
global tag | |
if name != "outline": | |
return | |
if attrs.get("type") == "rss": | |
urllib2.urlopen(sys.argv[2] + "/source", urllib.urlencode({"title": attrs["title"], "tags": tag, "spout": "spouts\\rss\\feed", "url": attrs["xmlUrl"]})).read() | |
else: | |
tag = attrs["text"] | |
def end_element(name): | |
pass | |
def char_data(data): | |
pass | |
p = xml.parsers.expat.ParserCreate() | |
p.StartElementHandler = start_element | |
p.EndElementHandler = end_element | |
p.CharacterDataHandler = char_data | |
if len(sys.argv) < 3: | |
print "Usage: %s subscriptions.xml http://example.com/selfoss" | |
sys.exit(1) | |
p.ParseFile(open(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment