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

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2. import re
  3.  
  4. class EntrepeneurMagRecipe(BasicNewsRecipe):
  5.     __license__  = 'GPL v3'
  6.     __author__ = 'kwetal'
  7.     language = 'en'
  8.     version = 1
  9.  
  10.     title = u'Entrepeneur Magazine'
  11.     publisher = u'Entrepreneur Media, Inc'
  12.     category = u'Business'
  13.     description = u'Online magazine on business, small business, management and economy'
  14.  
  15.     encoding = 'utf-8'
  16.  
  17.     no_stylesheets = True
  18.     remove_javascript = True
  19.  
  20.     keep_only_tags = []
  21.     keep_only_tags.append(dict(name = 'div', attrs = {'id': 'printbody'}))
  22.  
  23.     remove_tags = []
  24.     remove_tags.append(dict(name = 'base'))
  25.     remove_tags.append(dict(name = 'a', attrs = {'id': 'ctl00_privacyPolicyLink'}))
  26.  
  27.     remove_attributes = ['style']
  28.  
  29.     INDEX = 'http://www.entrepeneur.com'
  30.  
  31.     extra_css = '''
  32.                 body{font-family:verdana,arial,helvetica,geneva,sans-serif;}
  33.                 img {float: left; margin-right: 0.5em;}
  34.                 a, a[href] {text-decoration: none; color: blue;}
  35.                 div#ctl00_bodyContentPlaceHolder_articleHeader_divHeaderText {font-weight: bold;
  36.                     font-size: medium;}
  37.                 h1 {font-size: xx-large; font-weight: bold;}
  38.                 div.byline {font-size: small; color: #696969; font-weight: normal;}
  39.                 a.h2 {font-size: medium; font-weight: bold; color: #666666; text-decoration: none;
  40.                     margin-bottom: 0em;}
  41.                 '''
  42.  
  43.     conversion_options = {'comments': description, 'language': 'en',
  44.                           'publisher': publisher}
  45.  
  46.     def parse_index(self):
  47.         soup = self.index_to_soup('http://www.entrepreneur.com/magazine/entrepreneur/index.html')
  48.         answer = []
  49.  
  50.         div = soup.find('div', attrs = {'id': 'magfeature'})
  51.         if div:
  52.             a = div.find('a', attrs = {'class': 'headline'})
  53.             if a:
  54.                 title = self.tag_to_string(a)
  55.                 url = self.INDEX + a['href']
  56.                 description = a.findNextSibling(text = True)
  57.  
  58.                 articles = [{'title': title, 'date': None, 'url': url, 'description': description}]
  59.                 answer.append(('Cover Story', articles))
  60.  
  61.         for div in soup.findAll('div', attrs = {'class': 'subhead-special'}):
  62.             articles = []
  63.             for tag in div.findNextSiblings(['a', 'div'], attrs = {'class': ['h2', 'subhead-special']}):
  64.                 if tag.name == 'div' and tag['class'] == 'subhead-special':
  65.                     break
  66.                 if tag.name == 'a' and tag['class'] == 'h2':
  67.                     title = self.tag_to_string(tag)
  68.                     url = tag['href']
  69.                     description = tag.findNextSibling(text = True)
  70.                     articles.append({'title': title, 'date': None, 'url': url, 'description': description})
  71.             answer.append((self.tag_to_string(div), articles))
  72.  
  73.         return answer
  74.  
  75.  
  76.     def print_version(self, url):
  77.         id = url.rpartition('/')[2]
  78.  
  79.         return 'http://www.entrepreneur.com/article/printthis/' + id
  80.  
  81.     def preprocess_html(self, soup):
  82.         div = soup.find('div', attrs = {'id': 'printbody'})
  83.         if div:
  84.             a = div.find(lambda tag: tag.name == 'a' and len(tag.attrs) == 1)
  85.             if a:
  86.                 txt = a.findPreviousSibling(text = re.compile('URL:.*'))
  87.                 if txt:
  88.                     txt.extract()
  89.                 for br in a.findNextSiblings('br'):
  90.                     br.extract()
  91.                 a.extract()
  92.  
  93.         return soup
  94.  
  95.