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

  1. #!/usr/bin/env  python
  2. __license__   = 'GPL v3'
  3. __copyright__ = '2011, Miroslav Vasko zemiak@gmail.com'
  4.  
  5. '''
  6. .tyzden, a weekly news magazine (a week old issue)
  7. '''
  8. from calibre import strftime
  9. from calibre.web.feeds.news import BasicNewsRecipe
  10. from datetime import date
  11. import re
  12.  
  13. class TyzdenRecipe(BasicNewsRecipe):
  14.     __license__  = 'GPL v3'
  15.     __author__ = 'zemiak'
  16.     language = 'sk'
  17.     version = 1
  18.  
  19.     publisher = u'www.tyzden.sk'
  20.     category = u'Magazine'
  21.     description = u'A conservative weekly magazine. The latest free issue'
  22.  
  23.     today = date.today()
  24.     iso = today.isocalendar()
  25.     year = iso[0]
  26.     weeknum = iso[1]
  27.  
  28.     if (weeknum > 1):
  29.         weeknum -= 1
  30.  
  31.     title = u'tyzden'
  32.  
  33.     base_url_path = 'http://www.tyzden.sk/casopis/' + str(year) + '/' + str(weeknum)
  34.     base_url = base_url_path + '.html'
  35.  
  36.     oldest_article = 20
  37.     max_articles_per_feed = 100
  38.     remove_javascript = True
  39.  
  40.     use_embedded_content    = False
  41.     no_stylesheets = True
  42.  
  43.     keep_only_tags = []
  44.     keep_only_tags.append(dict(name = 'h1'))
  45.     keep_only_tags.append(dict(name = 'div', attrs = {'class': 'text_area top_nofoto'}))
  46.     keep_only_tags.append(dict(name = 'div', attrs = {'class': 'text_block'}))
  47.  
  48.     remove_tags_after = [dict(name = 'div', attrs = {'class': 'text_block'})]
  49.  
  50.     def find_sections(self):
  51.         soup = self.index_to_soup(self.base_url)
  52.         # find cover pic
  53.     imgdiv = soup.find('div', attrs = {'class': 'foto'})
  54.     if imgdiv is not None:
  55.             img = imgdiv.find('img')
  56.             if img is not None:
  57.                 self.cover_url = 'http://www.tyzden.sk/' + img['src']
  58.         # end find cover pic
  59.  
  60.         for s in soup.findAll('a', attrs={'href': re.compile(r'rubrika/.*')}):
  61.             yield (self.tag_to_string(s), s)
  62.  
  63.     def find_articles(self, soup):
  64.         for art in soup.findAllNext('a'):
  65.             if (not art['href'].startswith('casopis/')):
  66.                 break;
  67.  
  68.             url = art['href']
  69.             title = self.tag_to_string(art)
  70.             yield {
  71.                     'title': title, 'url':self.base_url_path + '/' + url, 'description':title,
  72.                     'date' : strftime('%a, %d %b'),
  73.                     }
  74.  
  75.     def parse_index(self):
  76.         feeds = []
  77.         for title, soup in self.find_sections():
  78.             feeds.append((title, list(self.find_articles(soup))))
  79.  
  80.         return feeds
  81.