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.recipe < prev    next >
Text File  |  2011-09-09  |  4KB  |  107 lines

  1. from calibre.web.feeds.recipes import BasicNewsRecipe
  2. #from calibre.ebooks.BeautifulSoup import BeautifulSoup
  3. from urllib import quote
  4. import re
  5.  
  6. class SportsIllustratedRecipe(BasicNewsRecipe) :
  7.     __author__  = 'kwetal'
  8.     __copyright__ = 'kwetal'
  9.     __license__ = 'GPL v3'
  10.     language = 'en'
  11.     description = 'Sports Illustrated'
  12.     version = 3
  13.     title          = u'Sports Illustrated'
  14.  
  15.     no_stylesheets = True
  16.     remove_javascript = True
  17.     use_embedded_content   = False
  18.  
  19.     INDEX = 'http://sportsillustrated.cnn.com/'
  20.     INDEX2 = 'http://sportsillustrated.cnn.com/vault/cover/home/index.htm'
  21.  
  22.     def parse_index(self):
  23.         answer = []
  24.         soup = self.index_to_soup(self.INDEX2)
  25.  
  26.         #Loop through all of the "latest" covers until we find one that actually has articles
  27.         for item in soup.findAll('div', attrs={'id': re.compile("ecomthumb_latest_*")}):
  28.             regex = re.compile('ecomthumb_latest_(\d*)')
  29.             result = regex.search(str(item))
  30.             current_issue_number = str(result.group(1))
  31.             current_issue_link = 'http://sportsillustrated.cnn.com/vault/cover/toc/' + current_issue_number + '/index.htm'
  32.             self.log('Checking this link for a TOC:  ', current_issue_link)
  33.  
  34.             index = self.index_to_soup(current_issue_link)
  35.             if index:
  36.                 if index.find('div', 'siv_noArticleMessage'):
  37.                     self.log('No TOC for this one.  Skipping...')
  38.                 else:
  39.                     self.log('Found a TOC...  Using this link')
  40.                     break
  41.  
  42.         # Find all articles.
  43.         list = index.find('div', attrs = {'class' : 'siv_artList'})
  44.         if list:
  45.             self.log ('found siv_artList')
  46.             articles = []
  47.             # Get all the artcles ready for calibre.
  48.             counter = 0
  49.             for headline in list.findAll('div', attrs = {'class' : 'headline'}):
  50.                 counter = counter + 1
  51.                 title = self.tag_to_string(headline.a) + '\n' + self.tag_to_string(headline.findNextSibling('div', attrs = {'class' : 'info'}))
  52.                 url = self.INDEX + headline.a['href']
  53.                 description = self.tag_to_string(headline.findNextSibling('a').div)
  54.                 article = {'title' : title, 'date' : u'', 'url'  : url, 'description' : description}
  55.                 articles.append(article)
  56.                 #if counter > 5:
  57.                     #break
  58.  
  59.             # See if we can find a meaningfull title
  60.             feedTitle = 'Current Issue'
  61.             hasTitle = index.find('div', attrs = {'class' : 'siv_imageText_head'})
  62.             if hasTitle :
  63.                 feedTitle = self.tag_to_string(hasTitle.h1)
  64.  
  65.             answer.append([feedTitle, articles])
  66.  
  67.         return answer
  68.  
  69.  
  70.     def print_version(self, url) :
  71.         # This is the url and the parameters that work to get the print version.
  72.         printUrl = 'http://si.printthis.clickability.com/pt/printThis?clickMap=printThis'
  73.         printUrl += '&fb=Y&partnerID=2356&url=' + quote(url)
  74.         return printUrl
  75.  
  76.         # However the original javascript also uses the following parameters, but they can be left out:
  77.         #   title : can be some random string
  78.         #   random : some random number, but I think the number of digits is important
  79.         #   expire : no idea what value to use
  80.         # 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
  81.  
  82.     '''def preprocess_html(self, soup):
  83.         header = soup.find('div', attrs = {'class' : 'siv_artheader'})
  84.         homeMadeSoup = BeautifulSoup('<html><head></head><body></body></html>')
  85.         body = homeMadeSoup.body
  86.  
  87.         # Find the date, title and byline
  88.         temp = header.find('td', attrs = {'class' : 'title'})
  89.         if temp :
  90.             date = temp.find('div', attrs = {'class' : 'date'})
  91.             if date:
  92.                 body.append(date)
  93.             if temp.h1:
  94.                 body.append(temp.h1)
  95.             if temp.h2 :
  96.                 body.append(temp.h2)
  97.             byline = temp.find('div', attrs = {'class' : 'byline'})
  98.             if byline:
  99.                 body.append(byline)
  100.  
  101.         # Find the content
  102.         for para in soup.findAll('div', attrs = {'class' : 'siv_artpara'}) :
  103.             body.append(para)
  104.  
  105.         return homeMadeSoup
  106.         '''
  107.