home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / histmag.recipe < prev    next >
Text File  |  2011-09-09  |  2KB  |  60 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 Histmag(BasicNewsRecipe):
  10.  
  11.     title = u'Histmag'
  12.     __author__ = 'matek09'
  13.     description = u"Artykuly historyczne i publicystyczne"
  14.     encoding = 'utf-8'
  15.     no_stylesheets = True
  16.     language = 'pl'
  17.     remove_javascript = True
  18.     #max_articles_per_feed = 1
  19.     remove_tags_before = dict(dict(name = 'div', attrs = {'id' : 'article'}))
  20.     remove_tags_after = dict(dict(name = 'h2', attrs = {'class' : 'komentarze'}))
  21.     #keep_only_tags =[]
  22.     #keep_only_tags.append(dict(name = 'h2'))
  23.     #keep_only_tags.append(dict(name = 'p'))
  24.  
  25.     remove_tags =[]
  26.     remove_tags.append(dict(name = 'p', attrs = {'class' : 'podpis'}))
  27.     remove_tags.append(dict(name = 'h2', attrs = {'class' : 'komentarze'}))
  28.     remove_tags.append(dict(name = 'img', attrs = {'src' : 'style/buttons/wesprzyjnas-1.jpg'}))
  29.  
  30.     preprocess_regexps = [(re.compile(r'</span>'), lambda match: '</span><br><br>'),
  31.                         (re.compile(r'<span>'), lambda match: '<br><br><span>')]
  32.     extra_css = '''
  33.                     .left {font-size: x-small}
  34.                     .right {font-size: x-small}
  35.                 '''
  36.  
  37.     def find_articles(self, soup):
  38.         articles = []
  39.         for div in soup.findAll('div', attrs={'class' : 'text'}):
  40.             articles.append({
  41.                 'title' : self.tag_to_string(div.h3.a),
  42.                 'url'   : 'http://www.histmag.org/' + div.h3.a['href'],
  43.                 'date'  : self.tag_to_string(div.next('p')).split('|')[0],
  44.                 'description' : self.tag_to_string(div.next('p', podpis=False)),
  45.                 })
  46.         return articles
  47.  
  48.     def parse_index(self):
  49.         soup = self.index_to_soup('http://histmag.org/?arc=4&dx=0')
  50.         feeds = []
  51.         feeds.append((u"Artykuly historyczne", self.find_articles(soup)))
  52.         soup = self.index_to_soup('http://histmag.org/?arc=5&dx=0')
  53.         feeds.append((u"Artykuly publicystyczne", self.find_articles(soup)))
  54.         soup = self.index_to_soup('http://histmag.org/?arc=1&dx=0')
  55.         feeds.append((u"Wydarzenia", self.find_articles(soup)))
  56.  
  57.         return feeds
  58.  
  59.  
  60.