Skip to content

Instantly share code, notes, and snippets.

@vincebusam
Created March 14, 2013 16:57
Show Gist options
  • Save vincebusam/5163032 to your computer and use it in GitHub Desktop.
Save vincebusam/5163032 to your computer and use it in GitHub Desktop.
Python script to upload your Google Reader subscriptions to selfoss.
#!/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