Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 06-22-2018, 11:49 PM   #1
lui1
Junior Member
lui1 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2017
Location: Los Angeles, CA
Device: Smart Phone
Update for Psychology Today

Here is an update for Psychology Today.

Psychology Today recipe
Code:
from calibre.web.feeds.recipes import BasicNewsRecipe

def check_words(words):
    return lambda x: x and frozenset(words.split()).intersection(x.split())

class PsychologyToday(BasicNewsRecipe):

    title = 'Psychology Today'
    __author__ = 'Kovid Goyal'

    description = ('This magazine takes information from the latest research'
                   ' in the field of psychology and makes it useful to people in their everyday'
                   ' lives. Its coverage encompasses self-improvement, relationships, the mind-body'
                   ' connection, health, family, the workplace and culture.')
    language = 'en'
    encoding = 'UTF-8'
    no_javascript = True
    no_stylesheets = True

    keep_only_tags = [
        dict(name='div', attrs={'data-type': 'article'})
    ]
    remove_tags = [
        dict(attrs={'id': 'pt-social-media'}),
    ]

    def parse_index(self):
        soup = self.index_to_soup('http://www.psychologytoday.com/magazine')
        div = soup.find(id='block-views-magazine-issues-block')
        a = div.find('h4').find('a')
        self.timefmt = ' [%s]' % self.tag_to_string(a).capitalize()
        soup = self.index_to_soup('http://www.psychologytoday.com' + a['href'])
        div = soup.find(role='main')
        self.cover_url = div.find('img', src=lambda x: x and '/field_magazine_cover/' in x)['src'].partition('?')[0]
        articles = []
        for x in div.findAll('div', {'class': check_words('collection__item')}):
            h = x.find(['h2', 'h3', 'h4', 'h5'], {'class': check_words('blog__title blog_entry__title')})
            title = self.tag_to_string(h)
            url = 'http://www.psychologytoday.com' + h.find('a')['href']
            self.log('\n', title, 'at', url)
            desc = x.find(['div', 'p'], {'class': check_words('collection__subtitle blog_entry__teaser')}).find(text=True)
            if desc:
                self.log(desc)
            else:
                desc = ''
            articles.append({'title': title, 'url': url, 'description': desc})
        return [('Current Issue', articles)]
lui1 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Psychology Today Recipe rainrdx Recipes 0 03-25-2013 07:17 PM
Request: Please update Psychology Today recipe underwarez Recipes 0 07-04-2012 01:50 PM
Fix for Psychology Today circa68 Recipes 4 10-31-2011 05:25 AM
Psychology Today website changed Shuichiro Recipes 9 08-31-2011 02:06 PM
Psychology today news feed failing to download Shuichiro Recipes 1 05-14-2011 05:11 AM


All times are GMT -4. The time now is 06:51 PM.


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