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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5.  
  6. '''
  7. republika.co.yu
  8. '''
  9.  
  10. import re
  11. from calibre.web.feeds.news import BasicNewsRecipe
  12.  
  13. class Republika(BasicNewsRecipe):
  14.     title                 = 'Republika'
  15.     __author__            = 'Darko Miletic'
  16.     description           = 'Glasilo gradjanskog samooslobadjanja. Protiv stihije straha, mrznje i nasilja'
  17.     publisher             = ' Zadruga Res Publica'
  18.     category              = 'news, politics, Serbia'    
  19.     language = 'sr'
  20.  
  21.     lang                  = 'sr-Latn-RS'
  22.     oldest_article        = 2
  23.     max_articles_per_feed = 100
  24.     no_stylesheets        = True
  25.     encoding              = 'cp1250'
  26.     use_embedded_content  = False
  27.     INDEX                 = u'http://www.republika.co.yu/'
  28.     extra_css = ' @font-face {font-family: "serif1"; src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)} body{font-family: serif1, serif} .article_description{font-family: serif1, serif} .naslov{font-size: x-large; font-weight: bold} .autor{font-size: small; font-weight: bold} '
  29.     
  30.     conversion_options = {
  31.                           'comment'          : description
  32.                         , 'tags'             : category
  33.                         , 'publisher'        : publisher
  34.                         , 'language'         : lang
  35.                         , 'pretty_print'     : True
  36.                         }
  37.      
  38.     preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
  39.  
  40.     keep_only_tags = [  dict(attrs={'class':'naslov'})
  41.                       , dict(attrs={'class':'text1'})
  42.                      ]
  43.  
  44.     remove_tags = [dict(name=['object','link','iframe','base','img'])]
  45.  
  46.     feeds = [(u'Svi clanci', INDEX)]
  47.  
  48.     def preprocess_html(self, soup):
  49.         attribs = [  'style','font','valign'
  50.                     ,'colspan','width','height'
  51.                     ,'rowspan','summary','align'
  52.                     ,'cellspacing','cellpadding'
  53.                     ,'frames','rules','border'
  54.                   ]
  55.         for item in soup.body.findAll(name=['table','td','tr','th','caption','thead','tfoot','tbody','colgroup','col']):
  56.             item.name = 'div'
  57.             for attrib in attribs:
  58.                 if item.has_key(attrib):
  59.                    del item[attrib]
  60.         return soup
  61.  
  62.     def parse_index(self):
  63.         totalfeeds = []
  64.         lfeeds = self.get_feeds()
  65.         for feedobj in lfeeds:
  66.             feedtitle, feedurl = feedobj
  67.             self.report_progress(0, _('Fetching feed')+' %s...'%(feedtitle if feedtitle else feedurl))
  68.             articles = []
  69.             soup = self.index_to_soup(feedurl)
  70.             for item in soup.findAll('a', attrs={'class':'naslovLink'}):
  71.                 url         = item['href']
  72.                 title       = self.tag_to_string(item)
  73.                 articles.append({
  74.                                       'title'      :title
  75.                                      ,'date'       :''
  76.                                      ,'url'        :url
  77.                                      ,'description':''
  78.                                     })
  79.             totalfeeds.append((feedtitle, articles))
  80.         return totalfeeds
  81.         
  82.