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

  1. __license__   = 'GPL v3'
  2. __copyright__ = '2008-2011, Darko Miletic <darko.miletic at gmail.com>'
  3. '''
  4. newyorker.com
  5. '''
  6.  
  7. from calibre.web.feeds.news import BasicNewsRecipe
  8.  
  9. class NewYorker(BasicNewsRecipe):
  10.     title                 = 'The New Yorker'
  11.     __author__            = 'Darko Miletic'
  12.     description           = 'The best of US journalism'
  13.     oldest_article        = 15
  14.     language              = 'en'
  15.     max_articles_per_feed = 100
  16.     no_stylesheets        = True
  17.     use_embedded_content  = False
  18.     publisher             = 'Conde Nast Publications'
  19.     category              = 'news, politics, USA'
  20.     encoding              = 'cp1252'
  21.     publication_type      = 'magazine'
  22.     masthead_url          = 'http://www.newyorker.com/css/i/hed/logo.gif'
  23.     extra_css             = """
  24.                                 body {font-family: "Times New Roman",Times,serif}
  25.                                 .articleauthor{color: #9F9F9F; 
  26.                                                font-family: Arial, sans-serif;
  27.                                                font-size: small; 
  28.                                                text-transform: uppercase}
  29.                                 .rubric,.dd,h6#credit{color: #CD0021;
  30.                                         font-family: Arial, sans-serif;
  31.                                         font-size: small;
  32.                                         text-transform: uppercase}
  33.                                 .descender:first-letter{display: inline; font-size: xx-large; font-weight: bold}
  34.                                 .dd,h6#credit{color: gray}
  35.                                 .c{display: block}
  36.                                 .caption,h2#articleintro{font-style: italic}
  37.                                 .caption{font-size: small}
  38.                             """
  39.  
  40.     conversion_options = {
  41.                           'comment'   : description
  42.                         , 'tags'      : category
  43.                         , 'publisher' : publisher
  44.                         , 'language'  : language
  45.                         }
  46.  
  47.     keep_only_tags = [
  48.                         dict(name='div', attrs={'class':'headers'})
  49.                        ,dict(name='div', attrs={'id':['articleheads','items-container','articleRail','articletext','photocredits']})
  50.                      ]
  51.     remove_tags    = [
  52.                          dict(name=['meta','iframe','base','link','embed','object'])
  53.                         ,dict(attrs={'class':['utils','socialUtils','articleRailLinks','icons'] })
  54.                         ,dict(attrs={'id':['show-header','show-footer'] })
  55.                      ]
  56.     remove_attributes = ['lang']
  57.     feeds             = [(u'The New Yorker', u'http://www.newyorker.com/services/mrss/feeds/everything.xml')]
  58.  
  59.     def print_version(self, url):
  60.         return url + '?printable=true'
  61.  
  62.     def image_url_processor(self, baseurl, url):
  63.         return url.strip()
  64.  
  65.     def get_cover_url(self):
  66.         cover_url = None
  67.         soup = self.index_to_soup('http://www.newyorker.com/magazine/toc/')
  68.         cover_item = soup.find('img',attrs={'id':'inThisIssuePhoto'})
  69.         if cover_item:
  70.            cover_url = 'http://www.newyorker.com' + cover_item['src'].strip()
  71.         return cover_url
  72.  
  73.     def preprocess_html(self, soup):
  74.         for item in soup.findAll(style=True):
  75.             del item['style']
  76.         auth = soup.find(attrs={'id':'articleauthor'})
  77.         if auth:
  78.            alink = auth.find('a')
  79.            if alink and alink.string is not None:
  80.               txt = alink.string
  81.               alink.replaceWith(txt)
  82.         return soup
  83.