home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_3912 < prev    next >
Encoding:
Text File  |  2009-10-14  |  3.7 KB  |  100 lines

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
  5.  
  6. '''
  7. monitorcg.com
  8. '''
  9.  
  10. import re
  11. from calibre.web.feeds.news import BasicNewsRecipe
  12. from calibre.ebooks.BeautifulSoup import Tag
  13.  
  14. class MonitorCG(BasicNewsRecipe):
  15.     title                 = 'Monitor online'
  16.     __author__            = 'Darko Miletic'
  17.     description           = 'News from Montenegro'
  18.     publisher             = 'MONITOR d.o.o. Podgorica'
  19.     category              = 'news, politics, Montenegro'
  20.     oldest_article        = 15
  21.     max_articles_per_feed = 150
  22.     no_stylesheets        = True
  23.     encoding              = 'utf-8'
  24.     use_embedded_content  = False
  25.     language = 'sr'
  26.  
  27.     lang                  ='sr-Latn-Me'
  28.     INDEX                 = 'http://www.monitorcg.com'
  29.  
  30.     extra_css = ' @font-face {font-family: "serif1";src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf)} body{font-family: serif1, serif} '
  31.  
  32.     conversion_options = {
  33.                           'comment'          : description
  34.                         , 'tags'             : category
  35.                         , 'publisher'        : publisher
  36.                         , 'language'         : lang
  37.                         , 'pretty_print'     : True
  38.                         }
  39.  
  40.     preprocess_regexps = [(re.compile(u'\u0110'), lambda match: u'\u00D0')]
  41.  
  42.     keep_only_tags = [dict(name='div', attrs={'id':'ja-current-content'})]
  43.  
  44.     remove_tags = [ dict(name=['object','link','embed'])
  45.                   , dict(attrs={'class':['buttonheading','article-section']})]
  46.  
  47.     remove_attributes = ['style','width','height','font','border','align']
  48.  
  49.     def adeify_images2(cls, soup):
  50.         for item in soup.findAll('img'):
  51.             for attrib in ['height','width','border','align','style']:
  52.                 if item.has_key(attrib):
  53.                    del item[attrib]
  54.             oldParent = item.parent
  55.             if oldParent.name == 'a':
  56.                oldParent.name == 'p'
  57.             myIndex = oldParent.contents.index(item)
  58.             brtag  = Tag(soup,'br')
  59.             oldParent.insert(myIndex+1,brtag)
  60.         return soup
  61.  
  62.     def preprocess_html(self, soup):
  63.         soup.html['xml:lang'] = self.lang
  64.         soup.html['lang']     = self.lang
  65.         mlang = Tag(soup,'meta',[("http-equiv","Content-Language"),("content",self.lang)])
  66.         soup.html.insert(0,mlang)
  67.         return self.adeify_images2(soup)
  68.  
  69.     def parse_index(self):
  70.         totalfeeds = []
  71.         soup = self.index_to_soup(self.INDEX)
  72.         cover_item = soup.find('div',attrs={'class':'ja-catslwi'})
  73.         if cover_item:
  74.            dt = cover_item['onclick'].partition("location.href=")[2]
  75.            curl = self.INDEX + dt.strip("'")
  76.            lfeeds = [(u'Svi clanci', curl)]
  77.         for feedobj in lfeeds:
  78.             feedtitle, feedurl = feedobj
  79.             self.report_progress(0, _('Fetching feed')+' %s...'%(feedtitle if feedtitle else feedurl))
  80.             articles = []
  81.             soup = self.index_to_soup(feedurl)
  82.             contitem = soup.find('div',attrs={'class':'article-content'})
  83.             if contitem:
  84.                 img = contitem.find('img')
  85.                 if img:
  86.                    self.cover_url = self.INDEX + img['src']
  87.                 for item in contitem.findAll('a'):
  88.                     url         = self.INDEX + item['href']
  89.                     title       = self.tag_to_string(item)
  90.                     articles.append({
  91.                                           'title'      :title
  92.                                          ,'date'       :''
  93.                                          ,'url'        :url
  94.                                          ,'description':''
  95.                                         })
  96.                 totalfeeds.append((feedtitle, articles))
  97.         return totalfeeds
  98.  
  99.  
  100.