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

  1. #!/usr/bin/env  python
  2. # -*- coding: cp1252 -*-
  3.  
  4. __license__   = 'GPL v3'
  5. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  6. '''
  7. politico.com
  8. '''
  9.  
  10. import re, traceback
  11.  
  12. from calibre.web.feeds.news import BasicNewsRecipe
  13.  
  14. class Politico(BasicNewsRecipe):
  15.  
  16.     title                 = 'Politico'
  17.     __author__            = 'Darko Miletic and Sujata Raman'
  18.     description           = 'Political news from USA'
  19.     publisher             = 'Capitol News Company, LLC'
  20.     category              = 'news, politics, USA'
  21.     oldest_article        = 7
  22.     max_articles_per_feed = 100
  23.     use_embedded_content  = False
  24.     no_stylesheets        = True
  25.     remove_javascript     = True
  26.     encoding              = 'UTF-8'
  27.     language = 'en'
  28.  
  29.     html2lrf_options = [
  30.                           '--comment', description
  31.                         , '--category', category
  32.                         , '--publisher', publisher
  33.                         , '--ignore-tables'
  34.                         ]
  35.  
  36.     html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"\nlinearize_tables=True'
  37.  
  38.     remove_tags       = [
  39.                          dict(name=['notags','embed','object','link','img']),
  40.                          ]
  41.  
  42.     extra_css = '''
  43.                 body{font-family:Arial,Sans-serif;}
  44.                 element.style{color:#FF0000;font-family:Arial,Sans-serif;}
  45.                 .author{color:#808080;font-size:x-small;}
  46.                 a{ color:#003399;}
  47.                 .byline{color:#696969 ; font-size:x-small;}
  48.                 .story{color:#000000;}
  49.                 td{color:#000000;}
  50.                 '''
  51.  
  52.     feeds = [
  53.               (u'Top Stories' , u'http://www.politico.com/rss/politicopicks.xml' )
  54.               ,(u'Congress'    , u'http://www.politico.com/rss/congress.xml'      )
  55.               ,(u'Ideas'       , u'http://www.politico.com/rss/ideas.xml'         )
  56.               ,(u'Life'        , u'http://www.politico.com/rss/life.xml'          )
  57.               ,(u'Lobbyists'   , u'http://www.politico.com/rss/lobbyists.xml'     )
  58.               ,(u'Pitboss'     , u'http://www.politico.com/rss/pitboss.xml'       )
  59.               ,(u'Politics'    , u'http://www.politico.com/rss/politics.xml'      )
  60.               ,(u'Roger Simon' , u'http://www.politico.com/rss/rogersimon.xml'    )
  61.               ,(u'Suite Talk'  , u'http://www.politico.com/rss/suitetalk.xml'     )
  62.               ,(u'Playbook'    , u'http://www.politico.com/rss/playbook.xml'      )
  63.               #(u'The Huddle'  , u'http://www.politico.com/rss/huddle.xml' )
  64.             ]
  65.  
  66.     def preprocess_html(self, soup):
  67.         mtag = '<meta http-equiv="Content-Language" content="en"/>'
  68.         soup.head.insert(0,mtag)
  69.         for item in soup.findAll(style=True):
  70.             del item['style']
  71.         return soup
  72.  
  73.     url_pat = re.compile(r'<a href="([^"]+print.*\.cfm[^"]+)"')
  74.  
  75.     def postprocess_html(self, soup, first):
  76.  
  77.             for tag in soup.findAll(name=['table', 'tr', 'td']):
  78.                 tag.name = 'div'
  79.             return soup
  80.  
  81.     def print_version(self, url):
  82.         raw = self.index_to_soup(url, raw=True)
  83.         try:
  84.             url = self.url_pat.search(raw).group(1)
  85.         except:
  86.             traceback.print_exc()
  87.             url = None
  88.         return url
  89.