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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2010, matek09, matek09@gmail.com'
  5. __copyright__ = 'Modified 2011,  Mariusz Wolek <mariusz_dot_wolek @ gmail dot com>'
  6.  
  7. from calibre.web.feeds.news import BasicNewsRecipe
  8. import re
  9.  
  10. class Wprost(BasicNewsRecipe):
  11.         EDITION = 0
  12.         FIND_LAST_FULL_ISSUE = True
  13.         EXCLUDE_LOCKED = True
  14.         ICO_BLOCKED = 'http://www.wprost.pl/G/icons/ico_blocked.gif'
  15.  
  16.         title = u'Wprost'
  17.         __author__ = 'matek09'
  18.         description = 'Weekly magazine'
  19.         encoding = 'ISO-8859-2'
  20.         no_stylesheets = True
  21.         language = 'pl'
  22.         remove_javascript = True
  23.  
  24.         remove_tags_before = dict(dict(name = 'div', attrs = {'id' : 'print-layer'}))
  25.         remove_tags_after = dict(dict(name = 'div', attrs = {'id' : 'print-layer'}))
  26.  
  27.         '''keep_only_tags =[]
  28.         keep_only_tags.append(dict(name = 'table', attrs = {'id' : 'title-table'}))
  29.         keep_only_tags.append(dict(name = 'div', attrs = {'class' : 'div-header'}))
  30.         keep_only_tags.append(dict(name = 'div', attrs = {'class' : 'div-content'}))
  31.         keep_only_tags.append(dict(name = 'div', attrs = {'class' : 'def element-autor'}))'''
  32.  
  33.         preprocess_regexps = [(re.compile(r'style="display: none;"'), lambda match: ''),
  34.         (re.compile(r'display: block;'), lambda match: ''),
  35.         (re.compile(r'\<td\>\<tr\>\<\/table\>'), lambda match: ''),
  36.         (re.compile(r'\<table .*?\>'), lambda match: ''),
  37.         (re.compile(r'\<tr>'), lambda match: ''),
  38.         (re.compile(r'\<td .*?\>'), lambda match: '')]
  39.  
  40.         remove_tags =[]
  41.         remove_tags.append(dict(name = 'div', attrs = {'class' : 'def element-date'}))
  42.         remove_tags.append(dict(name = 'div', attrs = {'class' : 'def silver'}))
  43.         remove_tags.append(dict(name = 'div', attrs = {'id' : 'content-main-column-right'}))
  44.  
  45.         extra_css = '''
  46.                                         .div-header {font-size: x-small; font-weight: bold}
  47.                                         '''
  48. #h2 {font-size: x-large; font-weight: bold}
  49.         def is_blocked(self, a):
  50.                 if a.findNextSibling('img') is None:
  51.                         return False
  52.                 else:
  53.                         return True
  54.  
  55.  
  56.  
  57.         def find_last_issue(self):
  58.                 soup = self.index_to_soup('http://www.wprost.pl/archiwum/')
  59.                 a = 0
  60.                 if self.FIND_LAST_FULL_ISSUE:
  61.                         ico_blocked = soup.findAll('img', attrs={'src' : self.ICO_BLOCKED})
  62.                         a = ico_blocked[-1].findNext('a', attrs={'title' : re.compile('Zobacz spis tre.ci')})
  63.                 else:
  64.                         a = soup.find('a', attrs={'title' : re.compile('Zobacz spis tre.ci')})
  65.                 self.EDITION = a['href'].replace('/tygodnik/?I=', '')
  66.                 self.cover_url = a.img['src']
  67.  
  68.  
  69.  
  70.         def parse_index(self):
  71.                 self.find_last_issue()
  72.                 soup = self.index_to_soup('http://www.wprost.pl/tygodnik/?I=' + self.EDITION)
  73.                 feeds = []
  74.                 for main_block in soup.findAll(attrs={'class':'main-block-s3 s3-head head-red3'}):
  75.                         articles = list(self.find_articles(main_block))
  76.                         if len(articles) > 0:
  77.                                 section = self.tag_to_string(main_block)
  78.                                 feeds.append((section, articles))
  79.                 return feeds
  80.  
  81.         def find_articles(self, main_block):
  82.                 for a in main_block.findAllNext( attrs={'style':['','padding-top: 15px;']}):
  83.                         if a.name in "td":
  84.                                 break
  85.                         if self.EXCLUDE_LOCKED & self.is_blocked(a):
  86.                                 continue
  87.                         yield {
  88.                                 'title' : self.tag_to_string(a),
  89.                                 'url'   : 'http://www.wprost.pl' + a['href'],
  90.                                 'date'  : '',
  91.                                 'description' : ''
  92.                                 }
  93.  
  94.