Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 01-05-2014, 05:32 PM   #1
aerodynamik
Enthusiast
aerodynamik doesn't litteraerodynamik doesn't litter
 
Posts: 43
Karma: 136
Join Date: Mar 2011
Device: Kindle Paperwhite
Inc Magazine recipe broken, here's a new one

Inc Magazine re-designed their website Inc.com and with it broke the recipe that is currently included in Calibre.

Here is a first version for a new recipe. It includes almost all articles, however lists all articles in one section, the website has only images for those without ALT text.

I will be updating the recipe over the next days.

Spoiler:
Code:
#!/usr/bin/env  python

__license__   = 'GPL v3'
__copyright__ = '2014, Nikolas Mangold-Takao <nmangold at gmail.com>'
__version__   = '0.10'

from calibre.web.feeds.recipes import BasicNewsRecipe

class IncMagazineRecipe(BasicNewsRecipe):
    language = 'en'
    version = 1

    __author__  = 'Nikolas Mangold-Takao <nmangold at gmail.com>'
  
    title = u'Inc Magazine'
    publisher = u'Mansueto Ventures LLC'
    category = u'News, Business'
    description = u'Free account required to browse website. Handbook of the American Entrepeneur'
    
    needs_subscription = True #signup is free, without account browsing is limited and recipe won't work

    use_embedded_content = False
    remove_empty_feeds = True

    no_stylesheets = True
    remove_javascript = True

    INDEX = 'http://www.inc.com/magazine'
    
    remove_tags_before = dict(name = 'div', attrs =  {'id': 'outercontainer'})
    remove_tags = [dict(name = 'div', attrs = {'id': 'morearticles'})]
    remove_tags_after = dict (name ='div', attrs = {'id': 'article-share-footer'})
    
    extra_css = '''
                div.byline {font-size: x-small; color: #696969; margin-top: 0.4em;}
                '''

    def get_browser(self):
        def has_login_name(form):
            try:
                form.find_control(name="email")
            except:
                return False
            else:
                return True

        br = BasicNewsRecipe.get_browser(self)
        if self.username is not None and self.password is not None:
            br.open('http://www.inc.com/login')
            br.select_form(predicate=has_login_name)
            br['email'   ] = self.username
            br['password'] = self.password
            br.submit()
        return br

    def parse_index(self):
        soup = self.index_to_soup(self.INDEX)
        
        feeds = []
        articles = []
        
        #We need for sure 'toc-top-l-column' and 'toc-bot-l-column'
        #I am not sure about 'toc-top-r-column and 'toc-bot-r-column', seems to be mostly ads
        for toc in soup.findAll('div', id=lambda x: x and x.endswith('-l-column')):
            for article in toc.findAll('div', {'class' : lambda x: x and x.startswith('toc-h')}): #h1-h2-h3
                link = article.find('a')
                if link is None:
                    continue
                article_title = self.tag_to_string(link)
                article_link  = link.get('href')
                articles.append({'title' : article_title, 'url' : article_link})
        feeds.append(('Articles', articles)) #TODO figure out sections
        return feeds
    
    def preprocess_html(self, soup):
        for alink in soup.findAll('a'):
            if alink.string is not None:
                tstr = alink.string
                alink.replaceWith(tstr)
        return soup
aerodynamik is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Business Week Magazine Recipe Broken agopalak Recipes 1 09-06-2013 06:47 AM
Built in calibre recipe broken : Prospect Magazine duluoz Recipes 1 05-24-2012 08:19 AM
People/US Magazine Mashup Recipe Broken SBiehler Recipes 1 09-13-2011 01:33 AM
TIME magazine recipe broken? alexxx Recipes 0 07-12-2011 03:45 AM
Recipe for Self Magazine (US) (need help) xXxXxXxXxXx Recipes 1 05-17-2011 05:16 PM


All times are GMT -4. The time now is 12:52 PM.


MobileRead.com is a privately owned, operated and funded community.