home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / greader.recipe < prev    next >
Text File  |  2011-09-09  |  2KB  |  36 lines

  1. import urllib, re, mechanize
  2. from calibre.web.feeds.recipes import BasicNewsRecipe
  3. from calibre import __appname__
  4.  
  5. class GoogleReader(BasicNewsRecipe):
  6.     title   = 'Google Reader'
  7.     description = 'This recipe fetches from your Google Reader account unread Starred items and unread Feeds you have placed in a folder via the manage subscriptions feature.'
  8.     needs_subscription = True
  9.     __author__ = 'davec, rollercoaster, Starson17'
  10.     base_url = 'http://www.google.com/reader/atom/'
  11.     oldest_article = 365
  12.     max_articles_per_feed = 250
  13.     get_options = '?n=%d&xt=user/-/state/com.google/read' % max_articles_per_feed
  14.     use_embedded_content = True
  15.  
  16.     def get_browser(self):
  17.         br = BasicNewsRecipe.get_browser(self)
  18.         if self.username is not None and self.password is not None:
  19.             request = urllib.urlencode([('Email', self.username), ('Passwd', self.password),
  20.                                         ('service', 'reader'), ('accountType', 'HOSTED_OR_GOOGLE'), ('source', __appname__)])
  21.             response = br.open('https://www.google.com/accounts/ClientLogin', request)
  22.             auth = re.search('Auth=(\S*)', response.read()).group(1)
  23.             cookies = mechanize.CookieJar()
  24.             br = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
  25.             br.addheaders = [('Authorization', 'GoogleLogin auth='+auth)]
  26.         return br
  27.  
  28.     def get_feeds(self):
  29.         feeds = []
  30.         soup = self.index_to_soup('http://www.google.com/reader/api/0/tag/list')
  31.         for id in soup.findAll(True, attrs={'name':['id']}):
  32.             url = id.contents[0]
  33.             feeds.append((re.search('/([^/]*)$', url).group(1),
  34.                           self.base_url + urllib.quote(url.encode('utf-8')) + self.get_options))
  35.         return feeds
  36.