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 10-10-2020, 12:57 PM   #1
rasteps
Zealot
rasteps began at the beginning.
 
Posts: 137
Karma: 10
Join Date: Sep 2010
Device: Kindle, Android phone
NY Times Cooking [recipe request]

Is anyone interested in tackling the NY Times Cooking page.

https://cooking.nytimes.com/topics/w...cook-this-week

I tried my hands at modifying the NY Times recipe to get this only to realize that I wasn't up to the task....
rasteps is offline   Reply With Quote
Old 10-15-2020, 12:31 PM   #2
gourav
Member
gourav doesn't littergourav doesn't litter
 
Posts: 14
Karma: 132
Join Date: Aug 2014
Device: Kindle Paperwhite 7th Gen
I gave it a shot and this is what I could come up with:

Code:
#!/usr/bin/env python
# vim:fileencoding=utf-8
from calibre.web.feeds.news import BasicNewsRecipe

class NYTCooking(BasicNewsRecipe):
    title          = 'NYT Cooking'
    oldest_article = 2
    max_articles_per_feed = 30
    auto_cleanup   = True
    auto_cleanup_keep = '//div[@class="recipe-intro"]|'\
                        '//div[@class="recipe-instructions"]|'
    
    def parse_index(self):
        url = 'https://cooking.nytimes.com/topics/what-to-cook-this-week'
        br = self.get_browser()
        response = br.open(url)
        html = response.read()
        soup = BeautifulSoup(html)

        articles = soup.find_all('div', class_='card-info-wrapper')
        feed = []

        for i in articles:
            article = {}
            article['url'] = i.find('a')['href']
            if article['url'].startswith('/'):
                article['url'] = 'https://cooking.nytimes.com' + article['url']
            article['title'] = i.find('h3').text.strip()
            author = i.find('p', class_='card-byline')
            article['author'] = author.text if author is not None else 'Unknown'
            feed.append(article)
            
        return [('Recipes', feed)]
I'm fairly new to this myself. So I was not able to get a clean output, but this works. Give it a shot and let me know whether it works for you or not.
gourav is offline   Reply With Quote
Advert
Old 10-16-2020, 02:12 AM   #3
rasteps
Zealot
rasteps began at the beginning.
 
Posts: 137
Karma: 10
Join Date: Sep 2010
Device: Kindle, Android phone
Quote:
Originally Posted by gourav View Post
I gave it a shot and this is what I could come up with:


I'm fairly new to this myself. So I was not able to get a clean output, but this works. Give it a shot and let me know whether it works for you or not.
That worked nicely. I wish I had the skill to do this.

You should submit this to Kovid for the official download.

Last edited by rasteps; 10-16-2020 at 11:45 AM.
rasteps is offline   Reply With Quote
Old 10-16-2020, 12:48 PM   #4
gourav
Member
gourav doesn't littergourav doesn't litter
 
Posts: 14
Karma: 132
Join Date: Aug 2014
Device: Kindle Paperwhite 7th Gen
I'm learning this for now. I have created some three recipes. Once I have a better understanding and am able to get a clean output with no errors, I'll probably submit.
gourav is offline   Reply With Quote
Old 08-17-2021, 10:38 AM   #5
rasteps
Zealot
rasteps began at the beginning.
 
Posts: 137
Karma: 10
Join Date: Sep 2010
Device: Kindle, Android phone
THIS should be submitted

Quote:
Originally Posted by gourav View Post
I gave it a shot and this is what I could come up with:

Code:
#!/usr/bin/env python
# vim:fileencoding=utf-8
from calibre.web.feeds.news import BasicNewsRecipe

class NYTCooking(BasicNewsRecipe):
    title          = 'NYT Cooking'
    oldest_article = 2
    max_articles_per_feed = 30
    auto_cleanup   = True
    auto_cleanup_keep = '//div[@class="recipe-intro"]|'\
                        '//div[@class="recipe-instructions"]|'
    
    def parse_index(self):
        url = 'https://cooking.nytimes.com/topics/what-to-cook-this-week'
        br = self.get_browser()
        response = br.open(url)
        html = response.read()
        soup = BeautifulSoup(html)

        articles = soup.find_all('div', class_='card-info-wrapper')
        feed = []

        for i in articles:
            article = {}
            article['url'] = i.find('a')['href']
            if article['url'].startswith('/'):
                article['url'] = 'https://cooking.nytimes.com' + article['url']
            article['title'] = i.find('h3').text.strip()
            author = i.find('p', class_='card-byline')
            article['author'] = author.text if author is not None else 'Unknown'
            feed.append(article)
            
        return [('Recipes', feed)]
I'm fairly new to this myself. So I was not able to get a clean output, but this works. Give it a shot and let me know whether it works for you or not.
@gourav I have been using this recipe for months now and it works great. I set it to download once a week on Sunday and I get a great weekly recipe magazine.

If you have no objections, I think this should be posted in the official list.
rasteps is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recipe Request: Hindustan times RSS feeds removed mitra Recipes 0 01-21-2016 01:17 AM
[Recipe Request] Financial Times iloveredbull Recipes 1 06-28-2015 05:45 AM
Seattle Times Recipe not cooking? daletsteele Recipes 1 12-31-2011 09:45 PM
Request for Recipe: Brisbane Times jtrappett Recipes 0 12-27-2010 10:50 PM
NY Times recipe -- request? maxbookworm Calibre 2 07-21-2010 04:07 PM


All times are GMT -4. The time now is 09:53 PM.


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