~stub/ubuntu/precise/calibre/devel

« back to all changes in this revision

Viewing changes to resources/recipes/sportsillustrated.recipe

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-04-12 11:29:25 UTC
  • mfrom: (42.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110412112925-c7171kt2bb5rmft4
Tags: 0.7.50+dfsg-2
* debian/control: Build with libpodofo-dev to enable PDF metadata.
  (Closes: #619632)
* debian/control: Add libboost1.42-dev build dependency. Apparently it is
  needed in some setups. (Closes: #619807)
* debian/rules: Call dh_sip to generate a proper sip API dependency, to
  prevent crashes like #616372 for partial upgrades.
* debian/control: Bump python-qt4 dependency to >= 4.8.3-2, which reportedly
  fixes crashes on startup. (Closes: #619701, #620125)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from calibre.web.feeds.recipes import BasicNewsRecipe
2
2
#from calibre.ebooks.BeautifulSoup import BeautifulSoup
3
3
from urllib import quote
 
4
import re
4
5
 
5
6
class SportsIllustratedRecipe(BasicNewsRecipe) :
6
7
    __author__  = 'kwetal'
16
17
    use_embedded_content   = False
17
18
 
18
19
    INDEX = 'http://sportsillustrated.cnn.com/'
 
20
    INDEX2 = 'http://sportsillustrated.cnn.com/vault/cover/home/index.htm'
19
21
 
20
22
    def parse_index(self):
21
23
        answer = []
22
 
        soup = self.index_to_soup(self.INDEX)
23
 
        # Find the link to the current issue on the front page. SI Cover
24
 
        cover = soup.find('img', attrs = {'alt' : 'Read All Articles', 'style' : 'vertical-align:bottom;'})
25
 
        if cover:
26
 
            currentIssue = cover.parent['href']
27
 
            if currentIssue:
28
 
                # Open the index of current issue
29
 
 
30
 
                index = self.index_to_soup(currentIssue)
31
 
                self.log('\tLooking for current issue in: ' + currentIssue)
32
 
                # Now let us see if they updated their frontpage
33
 
                nav = index.find('div', attrs = {'class': 'siv_trav_top'})
34
 
                if nav:
35
 
                    img = nav.find('img', attrs = {'src': 'http://i.cdn.turner.com/sivault/.element/img/1.0/btn_next_v2.jpg'})
36
 
                    if img:
37
 
                        parent = img.parent
38
 
                        if parent.name == 'a':
39
 
                            # They didn't update their frontpage; Load the next issue from here
40
 
                            href = self.INDEX + parent['href']
41
 
                            index = self.index_to_soup(href)
42
 
                            self.log('\tLooking for current issue in: ' + href)
43
 
 
 
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:
44
36
                if index.find('div', 'siv_noArticleMessage'):
45
 
                    nav = index.find('div', attrs = {'class': 'siv_trav_top'})
46
 
                    if nav:
47
 
                    # Their frontpage points to an issue without any articles; Use the previous issue
48
 
                        img = nav.find('img', attrs = {'src': 'http://i.cdn.turner.com/sivault/.element/img/1.0/btn_previous_v2.jpg'})
49
 
                        if img:
50
 
                            parent = img.parent
51
 
                            if parent.name == 'a':
52
 
                                href = self.INDEX + parent['href']
53
 
                                index = self.index_to_soup(href)
54
 
                                self.log('\tLooking for current issue in: ' + href)
55
 
 
56
 
 
57
 
                # Find all articles.
58
 
                list = index.find('div', attrs = {'class' : 'siv_artList'})
59
 
                if list:
60
 
                    articles = []
61
 
                    # Get all the artcles ready for calibre.
62
 
                    for headline in list.findAll('div', attrs = {'class' : 'headline'}):
63
 
                        title = self.tag_to_string(headline.a) + '\n' + self.tag_to_string(headline.findNextSibling('div', attrs = {'class' : 'info'}))
64
 
                        url = self.INDEX + headline.a['href']
65
 
                        description = self.tag_to_string(headline.findNextSibling('a').div)
66
 
                        article = {'title' : title, 'date' : u'', 'url'  : url, 'description' : description}
67
 
 
68
 
                        articles.append(article)
69
 
 
70
 
                    # See if we can find a meaningfull title
71
 
                    feedTitle = 'Current Issue'
72
 
                    hasTitle = index.find('div', attrs = {'class' : 'siv_imageText_head'})
73
 
                    if hasTitle :
74
 
                        feedTitle = self.tag_to_string(hasTitle.h1)
75
 
 
76
 
                    answer.append([feedTitle, articles])
 
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])
77
66
 
78
67
        return answer
79
68
 
82
71
        # This is the url and the parameters that work to get the print version.
83
72
        printUrl = 'http://si.printthis.clickability.com/pt/printThis?clickMap=printThis'
84
73
        printUrl += '&fb=Y&partnerID=2356&url=' + quote(url)
85
 
 
86
74
        return printUrl
87
75
 
88
76
        # However the original javascript also uses the following parameters, but they can be left out:
116
104
 
117
105
        return homeMadeSoup
118
106
        '''
119