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

  1. #!/usr/bin/env  python
  2.  
  3. __license__   = 'GPL v3'
  4. __copyright__ = '2010, matek09, matek09@gmail.com'
  5.  
  6. from calibre.web.feeds.news import BasicNewsRecipe
  7. import re
  8.  
  9. class Esensja(BasicNewsRecipe):
  10.  
  11.     title = u'Esensja'
  12.     __author__ = 'matek09'
  13.     description = 'Monthly magazine'
  14.     encoding = 'utf-8'
  15.     no_stylesheets = True
  16.     language = 'pl'
  17.     remove_javascript = True
  18.     HREF = '0'
  19.  
  20.     #keep_only_tags =[]
  21.     #keep_only_tags.append(dict(name = 'div', attrs = {'class' : 'article'})
  22.     remove_tags_before = dict(dict(name = 'div', attrs = {'class' : 't-title'}))
  23.     remove_tags_after = dict(dict(name = 'img', attrs = {'src' : '../../../2000/01/img/tab_bot.gif'}))
  24.  
  25.     remove_tags =[]
  26.     remove_tags.append(dict(name = 'img', attrs = {'src' : '../../../2000/01/img/tab_top.gif'}))
  27.     remove_tags.append(dict(name = 'img', attrs = {'src' : '../../../2000/01/img/tab_bot.gif'}))
  28.     remove_tags.append(dict(name = 'div', attrs = {'class' : 't-title2 nextpage'}))
  29.  
  30.     extra_css = '''
  31.                     .t-title {font-size: x-large; font-weight: bold; text-align: left}
  32.                     .t-author {font-size: x-small; text-align: left}
  33.                     .t-title2 {font-size: x-small; font-style: italic; text-align: left}
  34.                     .text {font-size: small; text-align: left}
  35.                     .annot-ref {font-style: italic; text-align: left}
  36.                 '''
  37.  
  38.     preprocess_regexps = [(re.compile(r'alt="[^"]*"'),
  39.                         lambda match: '')]
  40.  
  41.     def parse_index(self):
  42.         soup = self.index_to_soup('http://www.esensja.pl/magazyn/')
  43.         a = soup.find('a', attrs={'href' : re.compile('.*/index.html')})
  44.         year = a['href'].split('/')[0]
  45.         month = a['href'].split('/')[1]
  46.         self.HREF = 'http://www.esensja.pl/magazyn/' + year + '/' + month + '/iso/'
  47.         soup = self.index_to_soup(self.HREF + '01.html')
  48.         self.cover_url = 'http://www.esensja.pl/magazyn/' + year + '/' + month + '/img/ilustr/cover_b.jpg'
  49.         feeds = []
  50.         intro = soup.find('div', attrs={'class' : 'n-title'})
  51.         introduction = {'title' : self.tag_to_string(intro.a),
  52.                         'url' : self.HREF + intro.a['href'],
  53.                         'date' : '',
  54.                         'description' : ''}
  55.         chapter = 'Wprowadzenie'
  56.         subchapter = ''
  57.         articles = []
  58.         articles.append(introduction)
  59.         for tag in intro.findAllNext(attrs={'class': ['chapter', 'subchapter', 'n-title']}):
  60.             if tag.name in 'td':
  61.                 if len(articles) > 0:
  62.                     section = chapter
  63.                     if len(subchapter) > 0:
  64.                         section += ' - ' + subchapter
  65.                     feeds.append((section, articles))
  66.                     articles = []
  67.                 if tag['class'] == 'chapter':
  68.                     chapter = self.tag_to_string(tag).capitalize()
  69.                     subchapter = ''
  70.                 else:
  71.                     subchapter = self.tag_to_string(tag)
  72.                     subchapter = self.tag_to_string(tag)
  73.                 continue
  74.             articles.append({'title' : self.tag_to_string(tag.a), 'url' : self.HREF + tag.a['href'], 'date' : '', 'description' : ''})
  75.  
  76.             a = self.index_to_soup(self.HREF + tag.a['href'])
  77.             i = 1
  78.             while True:
  79.                 div = a.find('div', attrs={'class' : 't-title2 nextpage'})
  80.                 if div is not None:
  81.                     a = self.index_to_soup(self.HREF + div.a['href'])
  82.                     articles.append({'title' : self.tag_to_string(tag.a) + ' c. d. ' + str(i), 'url' : self.HREF + div.a['href'], 'date' : '', 'description' : ''})
  83.                     i = i + 1
  84.                 else:
  85.                     break
  86.  
  87.         return feeds
  88.