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

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2.  
  3. class TheBayCitizen(BasicNewsRecipe):
  4.     title                 = 'The Bay Citizen'
  5.     language              = 'en'
  6.     __author__            = 'noah'
  7.     description           = 'The Bay Citizen'
  8.     publisher             = 'The Bay Citizen'
  9.     INDEX                 = u'http://www.baycitizen.org'
  10.     category              = 'news'
  11.     oldest_article        = 2
  12.     max_articles_per_feed = 20
  13.     no_stylesheets        = True
  14.     masthead_url          = 'http://media.baycitizen.org/images/layout/logo1.png'
  15.     feeds                 = [('Main Feed', 'http://www.baycitizen.org/feeds/stories/')]
  16.     keep_only_tags        = [dict(name='div', attrs={'class':'story'})]
  17.     remove_tags           = [
  18.                              dict(name='div', attrs={'class':'socialBar'}),
  19.                              dict(name='div', attrs={'id':'text-resize'}),
  20.                              dict(name='div', attrs={'class':'story relatedContent'}),
  21.                              dict(name='div', attrs={'id':'comment_status_loading'}),
  22.                             ]
  23.  
  24.     def append_page(self, soup, appendtag, position):
  25.         pager = soup.find('a',attrs={'class':'stry-next'})
  26.         if pager:
  27.            nexturl = self.INDEX + pager['href']
  28.            soup2 = self.index_to_soup(nexturl)
  29.            texttag = soup2.find('div', attrs={'class':'body'})
  30.            for it in texttag.findAll(style=True):
  31.                del it['style']
  32.            newpos = len(texttag.contents)
  33.            self.append_page(soup2,texttag,newpos)
  34.            texttag.extract()
  35.            appendtag.insert(position,texttag)
  36.  
  37.  
  38.     def preprocess_html(self, soup):
  39.         for item in soup.findAll(style=True):
  40.             del item['style']
  41.         self.append_page(soup, soup.body, 3)
  42.         garbage = soup.findAll(id='story-pagination')
  43.         [trash.extract() for trash in garbage]
  44.         garbage = soup.findAll('em', 'cont-from-prev')
  45.         [trash.extract() for trash in garbage]
  46.         return soup
  47.