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

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2. from calibre.ebooks.BeautifulSoup import Tag
  3. import re
  4.  
  5. class JoopRecipe(BasicNewsRecipe):
  6.     __license__  = 'GPL v3'
  7.     __author__ = 'kwetal'
  8.     language = 'nl'
  9.     country = 'NL'
  10.     version = 1
  11.  
  12.     title = u'Joop'
  13.     publisher = u'Vara'
  14.     category = u'News, Politics, Discussion'
  15.     description = u'Political blog from the Netherlands'
  16.  
  17.     oldest_article = 7
  18.     max_articles_per_feed = 100
  19.     use_embedded_content = False
  20.  
  21.     no_stylesheets = True
  22.     remove_javascript = True
  23.  
  24.     keep_only_tags = []
  25.     keep_only_tags.append(dict(name = 'div', attrs = {'class': 'author_head clearfix photo'}))
  26.     keep_only_tags.append(dict(name = 'h2', attrs = {'class': 'columnhead smallline'}))
  27.     keep_only_tags.append(dict(name = 'div', attrs = {'class': re.compile('article.*')}))
  28.  
  29.     extra_css = '''
  30.                 body {font-family: verdana, arial, helvetica, geneva, sans-serif;}
  31.                 img {margin-right: 0.4em;}
  32.                 h3 {font-size: medium; font-style: italic; font-weight: normal;}
  33.                 h2 {font-size: xx-large; font-weight: bold}
  34.                 sub {color: #666666; font-size: x-small; font-weight: normal;}
  35.                 div.joop_byline {font-size: large}
  36.                 div.joop_byline_job {font-size: small; color: #696969;}
  37.                 div.joop_date {font-size: x-small; font-style: italic; margin-top: 0.6em}
  38.                 '''
  39.  
  40.     INDEX = 'http://www.joop.nl'
  41.  
  42.     conversion_options = {'comments': description, 'tags': category, 'language': language,
  43.                           'publisher': publisher}
  44.  
  45.     def parse_index(self):
  46.         sections = ['Politiek', 'Wereld', 'Economie', 'Groen', 'Media', 'Leven', 'Show', 'Opinies']
  47.         soup = self.index_to_soup(self.INDEX)
  48.         answer = []
  49.  
  50.         div = soup.find('div', attrs = {'id': 'footer'})
  51.         for section in sections:
  52.             articles = []
  53.             h2 = div.find(lambda tag: tag.name == 'h2' and tag.renderContents() == section)
  54.             if h2:
  55.                 ul = h2.findNextSibling('ul', 'linklist')
  56.                 if ul:
  57.                     for li in ul.findAll('li'):
  58.                         title = self.tag_to_string(li.a)
  59.                         url = self.INDEX + li.a['href']
  60.                         articles.append({'title': title, 'date': None, 'url': url, 'description': ''})
  61.  
  62.             answer.append((section, articles))
  63.  
  64.         return answer
  65.  
  66.     def preprocess_html(self, soup):
  67.         div = soup.find('div', 'author_head clearfix photo')
  68.         if div:
  69.             h2 = soup.find('h2')
  70.             if h2:
  71.                 h2.name = 'div'
  72.                 h2['class'] = 'joop_byline'
  73.                 span = h2.find('span')
  74.                 if span:
  75.                     span.name = 'div'
  76.                     span['class'] = 'joop_byline_job'
  77.                 div.replaceWith(h2)
  78.  
  79.         h2 = soup.find('h2', attrs = {'class': 'columnhead smallline'})
  80.         if h2:
  81.             txt = None
  82.             span = h2.find('span', 'info')
  83.             if span:
  84.                 txt = span.find(text = True)
  85.             div = Tag(soup, 'div', attrs = [('class', 'joop_date')])
  86.             div.append(txt)
  87.             h2.replaceWith(div)
  88.  
  89.         return soup
  90.  
  91.  
  92.