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

  1.  
  2. __license__   = 'GPL v3'
  3. __copyright__ = '2011, Darko Miletic <darko.miletic at gmail.com>'
  4. '''
  5. www.pecat.co.rs
  6. '''
  7.  
  8. import re
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10.  
  11. class Pecat_rs(BasicNewsRecipe):
  12.     title                 = 'Pecat'
  13.     __author__            = 'Darko Miletic'
  14.     description           = 'Internet portal slobodne Srbije'    
  15.     oldest_article        = 15
  16.     max_articles_per_feed = 100
  17.     language              = 'sr'
  18.     encoding              = 'utf-8'
  19.     no_stylesheets        = True
  20.     use_embedded_content  = True
  21.     masthead_url          = 'http://www.pecat.co.rs/wp-content/themes/zenko-v1/images/logo.jpg'
  22.     publication_type      = 'magazine'    
  23.     extra_css             = """ 
  24.                                 @font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)}
  25.                                 @font-face {font-family: "sans1";src:url(res:///opt/sony/ebook/FONT/tt0003m_.ttf)}
  26.                                 body{font-family: Arial,Helvetica,sans1,sans-serif}
  27.                                 img{display: block; margin-bottom: 1em; margin-top: 1em}
  28.                                 p{display: block; margin-bottom: 1em; margin-top: 1em}
  29.                             """
  30.  
  31.     conversion_options = {
  32.                           'comment'  : description
  33.                         , 'tags'     : 'politika, Srbija'
  34.                         , 'publisher': 'Pecat'
  35.                         , 'language' : language
  36.                         }
  37.  
  38.     preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
  39.  
  40.     feeds = [(u'Clanci', u'http://www.pecat.co.rs/feed/')]
  41.  
  42.     def preprocess_html(self, soup):
  43.         for item in soup.findAll(style=True):
  44.             del item['style']           
  45.         for item in soup.findAll('a'):
  46.             limg = item.find('img')
  47.             if item.string is not None:
  48.                str = item.string
  49.                item.replaceWith(str)
  50.             else:
  51.                if limg:
  52.                   limg.extract()
  53.                   item.replaceWith(limg)
  54.                else:
  55.                    str = self.tag_to_string(item)
  56.                    item.replaceWith(str)            
  57.         for item in soup.findAll('img'):
  58.             dad = item.findParent('p')
  59.             if dad:
  60.                mydad = dad.parent
  61.                myIndex = mydad.contents.index(dad)
  62.                item.extract()
  63.                mydad.insert(myIndex,item)
  64.         for item in soup.findAll('strong'):
  65.             dad = item.findParent('p')
  66.             if dad:
  67.                mydad = dad.parent
  68.                myIndex = mydad.contents.index(dad)
  69.                item.extract()
  70.                item.name='h4'
  71.                mydad.insert(myIndex,item)
  72.         return soup
  73.