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

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2.  
  3. class AdvancedUserRecipe1299694372(BasicNewsRecipe):
  4.     title                             = u'Instapaper'
  5.     __author__                  = 'Darko Miletic'
  6.     publisher                     = 'Instapaper.com'
  7.     category                      = 'info, custom, Instapaper'
  8.     oldest_article               = 365
  9.     max_articles_per_feed = 100
  10.     no_stylesheets        = True
  11.     remove_javascript     = True
  12.     remove_tags              = [
  13.     dict(name='div', attrs={'id':'text_controls_toggle'})
  14.     ,dict(name='script')
  15.     ,dict(name='div', attrs={'id':'text_controls'})
  16.     ,dict(name='div', attrs={'id':'editing_controls'})
  17.     ,dict(name='div', attrs={'class':'bar bottom'})
  18.      ]
  19.     use_embedded_content  = False
  20.     needs_subscription    = True
  21.     INDEX                 = u'http://www.instapaper.com'
  22.     LOGIN                 = INDEX + u'/user/login'
  23.  
  24.  
  25.     feeds          = [
  26.             (u'Instapaper Unread', u'http://www.instapaper.com/u'),
  27.             (u'Instapaper Starred', u'http://www.instapaper.com/starred')
  28.             ]
  29.  
  30.     def get_browser(self):
  31.         br = BasicNewsRecipe.get_browser()
  32.         if self.username is not None:
  33.             br.open(self.LOGIN)
  34.             br.select_form(nr=0)
  35.             br['username'] = self.username
  36.             if self.password is not None:
  37.                br['password'] = self.password
  38.             br.submit()
  39.         return br
  40.  
  41.     def parse_index(self):
  42.         totalfeeds = []
  43.         lfeeds = self.get_feeds()
  44.         for feedobj in lfeeds:
  45.             feedtitle, feedurl = feedobj
  46.             self.report_progress(0, 'Fetching feed'+' %s...'%(feedtitle if feedtitle else feedurl))
  47.             articles = []
  48.             soup = self.index_to_soup(feedurl)
  49.             for item in soup.findAll('div', attrs={'class':'cornerControls'}):
  50.                 #description = self.tag_to_string(item.div)
  51.                 atag = item.a
  52.                 if atag and atag.has_key('href'):
  53.                     url         = atag['href']
  54.                     articles.append({
  55.                                      'url'        :url
  56.                                     })
  57.             totalfeeds.append((feedtitle, articles))
  58.         return totalfeeds
  59.  
  60.     def print_version(self, url):
  61.         return 'http://www.instapaper.com' + url
  62.  
  63.     def populate_article_metadata(self, article, soup, first):
  64.         article.title  = soup.find('title').contents[0].strip()
  65.  
  66.     def postprocess_html(self, soup, first_fetch):
  67.         for link_tag in soup.findAll(attrs={"id" : "story"}):
  68.             link_tag.insert(0,'<h1>'+soup.find('title').contents[0].strip()+'</h1>')
  69.  
  70.         return soup
  71.