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 03-25-2013, 05:01 PM   #1
rainrdx
Connoisseur
rainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy bluerainrdx can differentiate black from dark navy blue
 
Posts: 55
Karma: 13316
Join Date: Jul 2012
Device: iPad
Fortune Magazine

Code:
import re
from calibre.web.feeds.recipes import BasicNewsRecipe
from collections import OrderedDict

class Fortune(BasicNewsRecipe):

    title       = 'Fortune Magazine'
    __author__  = 'Rick Shang'

    description = 'FORTUNE is a global business magazine that has been revered in its content and credibility since 1930. FORTUNE covers the entire field of business, including specific companies and business trends, prominent business leaders, and new ideas shaping the global marketplace.'
    language = 'en'
    category = 'news'
    encoding = 'UTF-8'
    keep_only_tags = [dict(attrs={'id':['storycontent']})]
    remove_tags = [dict(attrs={'class':['hed_side','socialMediaToolbarContainer']})]
    no_javascript = True
    no_stylesheets = True
    needs_subscription = True

    def get_browser(self):
        br = BasicNewsRecipe.get_browser(self)
        br.open('http://money.cnn.com/2013/03/21/smallbusiness/legal-marijuana-startups.pr.fortune/index.html')
        br.select_form(name="paywall-form")
        br['email'] = self.username
        br['password'] = self.password
        br.submit()
        return br

    def parse_index(self):
        articles = []
        soup0 = self.index_to_soup('http://money.cnn.com/magazines/fortune/')

	
	#Go to the latestissue
	soup = self.index_to_soup(soup0.find('div',attrs={'class':'latestissue'}).find('a',href=True)['href'])

	#Find cover & date
	cover_item = soup.find('div', attrs={'id':'cover-story'})
	cover = cover_item.find('img',src=True)
	self.cover_url = cover['src']
	date = self.tag_to_string(cover_item.find('div', attrs={'class':'tocDate'})).strip()
	self.timefmt = u' [%s]'%date


        feeds = OrderedDict()
	section_title = ''
	
	#checkout the cover story
	articles = []
	coverstory=soup.find('div', attrs={'class':'cnnHeadline'})
	title=self.tag_to_string(coverstory.a).strip()
	url=coverstory.a['href']
	desc=self.tag_to_string(coverstory.findNext('p', attrs={'class':'cnnBlurbTxt'}))
	articles.append({'title':title, 'url':url, 'description':desc, 'date':''})
	feeds['Cover Story'] = []
	feeds['Cover Story'] += articles

        for post in soup.findAll('div', attrs={'class':'cnnheader'}):
		section_title = self.tag_to_string(post).strip()
		articles = []

		ul=post.findNext('ul')
		for link in ul.findAll('li'):
			links=link.find('h2')
			title=self.tag_to_string(links.a).strip()
			url=links.a['href']
			desc=self.tag_to_string(link.find('p', attrs={'class':'cnnBlurbTxt'}))
			articles.append({'title':title, 'url':url, 'description':desc, 'date':''})
		
		if articles:
			if section_title not in feeds:
	                    feeds[section_title] = []
			feeds[section_title] += articles

        ans = [(key, val) for key, val in feeds.iteritems()]
        return ans

Last edited by rainrdx; 03-25-2013 at 05:11 PM.
rainrdx is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortune Magazine nitsuj123 Recipes 5 03-15-2013 07:10 AM
Fortune Magazine Suggests iPad Mini to Appear October 17(?) Batman Jr. Apple Devices 9 10-03-2012 11:41 AM
UK Kindle free book: Fortune's Deception: Fortune, Book 1 greencat Deals and Resources (No Self-Promotion or Affiliate Links) 1 05-15-2011 03:25 AM
The Magazine is Dead. Long Live the Magazine! kennyc News 17 11-01-2010 12:36 PM
Magazine FREEBIES - HUB magazine: Weekly Tales of SF Dr. Drib Deals and Resources (No Self-Promotion or Affiliate Links) 3 11-07-2009 12:07 PM


All times are GMT -4. The time now is 04:55 AM.


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