Tuesday, June 25, 2013

Google Reader backup script

The "subscriptions.xml" file can be obtained from Google TakeOut export. It is just an OPML file that might be imported into another RSS Reader.
#!/usr/bin/env python

import os
import urllib
import re


def downloadData(feed):
 feed = urllib.quote_plus(feed)
 url = "http://www.google.com/reader/api/0/stream/contents/feed/"+feed+"?n=9999"
 urllib.urlretrieve(url, feed)

def parseFile():
 result = []
 f = open("subscriptions.xml", "r")
 xmlUrl = re.compile(r'.*xmlUrl="(.*?)"')
 for line in f.readlines():
  m = xmlUrl.match(line)
  if m!=None:
   result.append(m.group(1))
 return result
   
if __name__=="__main__":
 feeds = parseFile()
 for feed in feeds:
  downloadData(feed)

No comments:

Post a Comment