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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5. '''
  6. en.wikinews.org
  7. '''
  8.  
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class WikiNews(BasicNewsRecipe):
  12.     title                 = 'Wikinews'
  13.     __author__            = 'Darko Miletic'
  14.     description           = 'News from wikipedia'
  15.     category              = 'news, world'
  16.     oldest_article        = 7
  17.     max_articles_per_feed = 100
  18.     publisher             = 'Wiki'
  19.     no_stylesheets        = True
  20.     use_embedded_content  = False
  21.     encoding              = 'utf-8'
  22.     remove_javascript     = True
  23.     language = 'en'
  24.  
  25.     
  26.     html2lrf_options = [
  27.                           '--comment', description
  28.                         , '--category', category
  29.                         , '--publisher', publisher
  30.                         ]
  31.     
  32.     html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"' 
  33.  
  34.     keep_only_tags = [ 
  35.                         dict(name='h1', attrs={'id':'firstHeading'}) 
  36.                        ,dict(name='div', attrs={'id':'bodyContent'}) 
  37.                      ]
  38.     
  39.     remove_tags = [
  40.                     dict(name='link')
  41.                    ,dict(name='div',attrs={'id':['printfooter','catlinks','footer']})
  42.                    ,dict(name='div',attrs={'class':['thumb left','thumb right']})
  43.                   ]
  44.  
  45.     remove_tags_after = dict(name='h2')
  46.                   
  47.     feeds = [(u'News', u'http://feeds.feedburner.com/WikinewsLatestNews')]
  48.  
  49.     def get_article_url(self, article):
  50.         artl  = article.get('link',  None)
  51.         rest, sep, article_id  = artl.rpartition('/')
  52.         return 'http://en.wikinews.org/wiki/' + article_id
  53.             
  54.     def print_version(self, url):
  55.         rest, sep, article_id  = url.rpartition('/')
  56.         return 'http://en.wikinews.org/w/index.php?title=' + article_id + '&printable=yes'
  57.  
  58.     def get_cover_url(self):
  59.         return 'http://upload.wikimedia.org/wikipedia/commons/b/bd/Wikinews-logo-en.png'
  60.  
  61.     def preprocess_html(self, soup):
  62.         mtag = '<meta http-equiv="Content-Language" content="en"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'
  63.         soup.head.insert(0,mtag)
  64.         btag = soup.find('div',attrs={'id':'bodyContent'})
  65.         for item in btag.findAll('div'):
  66.             item.extract()        
  67.         for item in btag.findAll('h2'):
  68.             item.extract()        
  69.         for item in soup.findAll(style=True):
  70.             del item['style']
  71.         for item in soup.findAll(font=True):
  72.             del item['font']
  73.         return soup
  74.         
  75.