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

  1. from calibre.web.feeds.recipes import BasicNewsRecipe
  2. from calibre.ebooks.BeautifulSoup import BeautifulSoup
  3. #from random import randint
  4. from urllib import quote
  5.  
  6. class SportsIllustratedColumnistsRecipe(BasicNewsRecipe) :
  7.     title          = u'Sports Illustrated Columnists'
  8.     __author__  = u'kwetal'
  9.     __license__ = u'GPL v3'
  10.     language = 'en'
  11.     version = 2
  12.  
  13.     oldest_article = 7
  14.     max_articles_per_feed = 100
  15.     no_stylesheets = True
  16.     remove_javascript = True
  17.  
  18.     feeds = []
  19.     # RSS sources found at http://sportsillustrated.cnn.com/services/rss/
  20.     feeds.append((u'Jon Heyman', u'http://rss.cnn.com/rss/si_jon_heyman.rss'))
  21.     feeds.append((u'Austin Murphy', u'http://rss.cnn.com/rss/si_austin_murphy.rss'))
  22.     feeds.append((u'Lars Anderson', u'http://rss.cnn.com/rss/si_lars_anderson.rss'))
  23.     feeds.append((u'Melissa Segura', u'http://rss.cnn.com/rss/si_melissa_segura.rss'))
  24.     feeds.append((u'Peter King', u'http://rss.cnn.com/rss/si_peter_king.rss'))
  25.     feeds.append((u'Scott Wraight', u'http://rss.cnn.com/rss/si_scott_wraight.rss'))
  26.  
  27.     def print_version(self, url) :
  28.         # This is the url and the parameters that work to get the print version.
  29.         printUrl = 'http://si.printthis.clickability.com/pt/printThis?clickMap=printThis'
  30.         printUrl += '&fb=Y&partnerID=2356&url=' + quote(url)
  31.  
  32.         return printUrl
  33.  
  34.         # However the original javascript also uses the following parameters, but they can be left out:
  35.         #   title : can be some random string
  36.         #   random : some random number, but I think the number of digits is important
  37.         #   expire : no idea what value to use
  38.         # All this comes from the Javascript function that redirects to the print version. It's called PT() and is defined in the file 48.js
  39.  
  40.     def preprocess_html(self, soup) :
  41.         temp = soup.find('div', attrs = {'class' : 'cnnstoryheadline'})
  42.         if temp :
  43.             # It's an article, make a valid content container
  44.             homeMadeSoup = BeautifulSoup('<html><head></head><body></body></html>')
  45.             body = homeMadeSoup.find('body')
  46.  
  47.             headline = temp.find('h1')
  48.             if headline :
  49.                 body.append(headline)
  50.  
  51.             for td in soup.findAll('td', attrs = {'class' : 'cnnstorycontentarea'}) :
  52.                 for p in td.findAll('p') :
  53.                     body.append(p)
  54.  
  55.             return homeMadeSoup
  56.         else :
  57.             # It's a TOC, just return the whole lot
  58.             return soup
  59.  
  60.  
  61.