Skip to content

Instantly share code, notes, and snippets.

@thesnapdragon
Created January 30, 2014 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thesnapdragon/8721864 to your computer and use it in GitHub Desktop.
Save thesnapdragon/8721864 to your computer and use it in GitHub Desktop.
old Python script that fetched Google Reader unread feeds count
#!/usr/bin/env python
import urllib
import urllib2
import xml.etree.ElementTree as ET
def main():
username = 'EMAILADDRESS'
password = 'PASSWORD'
# Authenticate to obtain SID
auth_url = 'https://www.google.com/accounts/ClientLogin'
auth_req_data = urllib.urlencode({'Email': username,
'Passwd': password,
'service': 'reader'})
auth_req = urllib2.Request(auth_url, data=auth_req_data)
auth_resp = urllib2.urlopen(auth_req)
auth_resp_content = auth_resp.read()
auth_resp_dict = dict(x.split('=') for x in auth_resp_content.split('\n') if x)
auth_token = auth_resp_dict["Auth"]
# Create a cookie in the header using the SID
header = {}
header['Authorization'] = 'GoogleLogin auth=%s' % auth_token
reader_base_url = 'http://www.google.com/reader/api/0/unread-count?%s'
reader_req_data = urllib.urlencode({'all': 'true', 'output': 'xml'})
reader_url = reader_base_url % (reader_req_data)
reader_req = urllib2.Request(reader_url, None, header)
reader_resp = urllib2.urlopen(reader_req)
reader_resp_content = reader_resp.read()
root = ET.fromstring(reader_resp_content)
objects = []
if len(root.find('list').findall('object')) == 0:
print 0
return
for child in root.find('list').findall('object'):
objects.append(child)
for object in objects:
if object.find('string').text.find('/state/com.google/reading-list') != -1:
for number in object.findall('number'):
if number.get('name') == 'count':
print number.text
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment