Skip to content

Commit

Permalink
add methods to retrieve starred items
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtazz committed Aug 4, 2009
1 parent d627414 commit ded4467
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions reader.py
Expand Up @@ -12,21 +12,49 @@ class GoogleReader:
def __init__(self, login, password):
self.login = login
self.password = password
self.authurl = "https://www.google.com/accounts/ClientLogin"
self.re_auth = re.compile("Auth=")
self.auth_url = "https://www.google.com/accounts/ClientLogin"
self.re_auth = re.compile("SID=")
self.sid = self.authenticate(self.login,self.password)
self.header = {}
self.header = self.create_header(self.header,self.sid)

def authenticate(self,login,password):
''' method to authenticate to google'''
parameters = {'Email' : login,'Passwd' : password,'accountType' : 'HOSTED_OR_GOOGLE',
'service' : 'reader', 'source' : 'googlereader2instapaper' }
parameters = { 'Email' : login,
'Passwd' : password,
'accountType' : 'HOSTED_OR_GOOGLE',
'service' : 'reader',
'source' : 'googlereader2instapaper',
'continue': 'http://www.google.com' }
headerdata = urllib.urlencode(parameters)
try:
request = urllib2.Request(self.authurl, headerdata)
request = urllib2.Request(self.auth_url, headerdata)
response = urllib2.urlopen(request).read().split("\n")
for r in response:
if self.re_auth.match(r):
return r.split("=")[1]
except IOError, e:
print e
return -1
return -1

def create_header(self, header, sid):
''' Method to create the header which is used afterwards for authentication '''
header = {'User-agent' : 'python'}
header['Cookie'] = 'Name=SID;SID=%s;Domain=.google.com;Path=/;Expires=160000000000' % sid
return header

def get_starred_items(self,header,sid=False):
''' method to get starred items from google reader '''
if sid:
id = sid
else:
id = self.sid
starred_url = "http://www.google.com/reader/atom/user/-/state/com.google/starred"
try:
request = urllib2.Request(starred_url, None, header)
response = urllib2.urlopen(request).read()
return response
except IOError, e:
print e
return -1

0 comments on commit ded4467

Please sign in to comment.