home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_3826 < prev    next >
Encoding:
Text File  |  2010-05-17  |  2.8 KB  |  77 lines

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2009-2010, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. www.instapaper.com
  5. '''
  6.  
  7. import urllib
  8. from calibre import strftime
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class Instapaper(BasicNewsRecipe):
  12.     title                 = 'Instapaper.com'
  13.     __author__            = 'Darko Miletic'
  14.     description           = '''Personalized news feeds. Go to instapaper.com to
  15.                                setup up your news. Fill in your instapaper
  16.                                username, and leave the password field
  17.                                below blank.'''
  18.     publisher             = 'Instapaper.com'
  19.     category              = 'news, custom'
  20.     oldest_article        = 7
  21.     max_articles_per_feed = 100
  22.     no_stylesheets        = True
  23.     use_embedded_content  = False
  24.     needs_subscription    = True
  25.     INDEX                 = u'http://www.instapaper.com'
  26.     LOGIN                 = INDEX + u'/user/login'
  27.  
  28.     conversion_options = {
  29.                           'comment'   : description
  30.                         , 'tags'      : category
  31.                         , 'publisher' : publisher
  32.                         }
  33.  
  34.     feeds = [
  35.               (u'Unread articles' , INDEX + u'/u'      )
  36.              ,(u'Starred articles', INDEX + u'/starred')
  37.             ]
  38.  
  39.     def get_browser(self):
  40.         br = BasicNewsRecipe.get_browser()
  41.         if self.username is not None:
  42.             br.open(self.LOGIN)
  43.             br.select_form(nr=0)
  44.             br['username'] = self.username
  45.             if self.password is not None:
  46.                br['password'] = self.password
  47.             br.submit()
  48.         return br
  49.  
  50.     def parse_index(self):
  51.         totalfeeds = []
  52.         lfeeds = self.get_feeds()
  53.         for feedobj in lfeeds:
  54.             feedtitle, feedurl = feedobj
  55.             self.report_progress(0, _('Fetching feed')+' %s...'%(feedtitle if feedtitle else feedurl))
  56.             articles = []
  57.             soup = self.index_to_soup(feedurl)
  58.             for item in soup.findAll('div', attrs={'class':'titleRow'}):
  59.                 description = self.tag_to_string(item.div)
  60.                 atag = item.a
  61.                 if atag and atag.has_key('href'):
  62.                     url         = atag['href']
  63.                     title       = self.tag_to_string(atag)
  64.                     date        = strftime(self.timefmt)
  65.                     articles.append({
  66.                                       'title'      :title
  67.                                      ,'date'       :date
  68.                                      ,'url'        :url
  69.                                      ,'description':description
  70.                                     })
  71.             totalfeeds.append((feedtitle, articles))
  72.         return totalfeeds
  73.  
  74.     def print_version(self, url):
  75.         return self.INDEX + '/text?u=' + urllib.quote(url)
  76.  
  77.