I use Google Reader as my feed aggregator for quite some time now, and I like it very much as it allows me to read my news feed from several devices (including my mobile phone but unfortunately excluding my Nokia N810 due to limitied screen size and performance). I always wanted to access the collected news in a script, just do do other stuff with the feeds. I.e. feed the news to a TTS and read them back to me or create my own personal feed with news from Google Reader mixed with headlines of incoming mails and short messages on my phone. Basically, to use Google Reader as a source for news as one part of a "personal information feed", like a mash-up. I googled around a bit and found this unofficial Google Reader API. So here is how you might script that with python.
First of all, you have to log in to Google via the login page and save the cookie to access Google's services. Login is only poosible through SSL. The following python function receives your Google login and password and gives you back the cookie string:
def get_googlereader_cookie(username, password):
# Login to Google
conns = httplib.HTTPSConnection("www.google.com")
params = urllib.urlencode({'Email': username, 'Passwd' : password, 'service': 'reader', 'source': 'Python Browser 1.0', 'continue': 'http://www.google.com/'})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
conns.request("POST", "/accounts/ClientLogin", params, headers)
r0 = conns.getresponse()
if r0.status != 200:
print r0.read()
return 'Error'
data0 = r0.read()
conns.close()
sid = data0.split("\n")[0].split("=")[1]
cookie = 'SID="' + sid + '"; $domain=.google.com; $path=/; $expires=1600000000;'
return cookie
Afterwards you have access to the API. To use the Google Reader API you have to provide another ID, which is the ID that appears in your public page of your shared items (click on "view public page" near "Your shared items" in the "Settings->Folder and Tags" tab of the Google Reader GUI). The ID is the last part of the URL of that page, normally 20 digits. Pass the cookie and the ID to the following function:
def get_googlereader_feed(userid, cookie):
conn = httplib.HTTPConnection("www.google.com")
headers = {"Cookie": cookie, "Accept": "text/plain"}
conn.request("GET", "/reader/atom/user/"+ userid + "/state/com.google/reading-list", None, headers)
r1 = conn.getresponse()
if r1.status != 200:
print r1.read()
return 'Error'
data1 = r1.read()
conn.close()
return data1
If everything is OK you should receive the feed data as an atom feed now. You can parse this feed with your favorite XML parser in python, for example the Universal Feed Parser.
As a special goodie, I will show you a way how to parse that feed on your Series60 device with Python for S60. I tried several ways to parse XML in my Nokia phone, none of them worked really fine. Then I found a very simple but very useful XML parser for S60 using regular expressions only. I could finally parse Google Reader's atom feeds with this parser just by copying the XMLParser.py to the same directory as my script. Of course it will work with your desktop python, too. :-)
Here is my full script to print out the feed's headlines: googlereader.py
(Copy the XMLParser.py from here in the same directory before starting the script.)
Have fun!