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-08-2023, 04:10 PM   #1
FacetiousKnave
Unconscionable
FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.
 
FacetiousKnave's Avatar
 
Posts: 76
Karma: 20000
Join Date: Sep 2022
Location: Helsinki
Device: Kindle
Trying to write a recipe for Aeon.com

My coding skills are rather deplorable.

I might have re-written this code 50 times but it never works.

The recipe should be quite simple. These are the premises.

1. RSS FEED source: https://aeon.co/feed.rss
2. Exclude "videos".
3. Output EPUB

PHP Code:
import re

from calibre
.ebooks.conversion.plumber import Plumber
from calibre
.web.feeds.recipes import BasicNewsRecipe

class AeonRecipe(BasicNewsRecipe):
    
title 'Aeon'
    
__author__ 'FacetiousKnave'
    
description 'This recipe fetches articles from Aeon and outputs an EPUB file'
    
use_embedded_content False
    remove_tags 
= [
        
dict(name='iframe')
    ]

    
def parse_index(self):
        
items self.index_to_soup('https://aeon.co/feed.rss').find_all('item')
        for 
item in items:
            
title item.title.text
            
if 'video' not in title.lower():
                
url item.link.text
                date 
item.pubdate.text
                self
.add_article(titleurldatetext=self.fetch_article(url))
                
    
def postprocess_html(selfsoupfirst_fetch):
        
# Remove unwanted tags
        
for tag in self.remove_tags:
            for 
t in soup.find_all(**tag):
                
t.decompose()
        return 
soup 
What am I doing wrong?
FacetiousKnave is offline   Reply With Quote
Old 01-09-2023, 12:27 AM   #2
unkn0wn
Evangelist
unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.
 
Posts: 442
Karma: 82686
Join Date: May 2021
Device: kindle
just use 'create basic news recipe' and add feed.. it does everything for you. Why parse?
add this if you want to remove video articles.. do you specifically want to remove articles with 'videos' in title only?
Code:
    def print_version(self, url):
        if '/videos/' in url:
            return ''
        else:
            return url

Last edited by unkn0wn; 01-09-2023 at 12:37 AM.
unkn0wn is online now   Reply With Quote
Old 01-09-2023, 12:43 AM   #3
unkn0wn
Evangelist
unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.unkn0wn can do the Funky Gibbon.
 
Posts: 442
Karma: 82686
Join Date: May 2021
Device: kindle
this works. removing video articles is unnecessary, you could just skip over to next article.

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

class AdvancedUserRecipe673238347(BasicNewsRecipe):
    title          = 'Aeon'
    oldest_article = 30
    max_articles_per_feed = 100
    auto_cleanup   = True

    feeds          = [
        ('aeon', 'https://aeon.co/feed.rss'),
    ]
    
    def print_version(self, url):
        if '/videos/' in url:
            return ''
        else:
            return url
unkn0wn is online now   Reply With Quote
Old 01-09-2023, 04:36 PM   #4
FacetiousKnave
Unconscionable
FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.FacetiousKnave can self-interpret dreams as they happen.
 
FacetiousKnave's Avatar
 
Posts: 76
Karma: 20000
Join Date: Sep 2022
Location: Helsinki
Device: Kindle
Wow this works perfect, thank you a lot!
FacetiousKnave is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Would someone be able to write up a custom recipe TheBanana Recipes 0 09-21-2022 03:27 AM
[Recipe Request] Aeon magazine duluoz Recipes 1 05-12-2020 09:57 AM
Aeon.co - Recipe download failed - CERTIFICATE_VERIFY_FAILED emanu Recipes 13 07-16-2016 12:29 AM
Re-Write for Handelsblatt Recipe (German Business Newspaper) hegi Recipes 1 02-14-2015 07:40 AM
HOW TO WRITE A RECIPE hermanus Recipes 1 04-02-2013 12:10 PM


All times are GMT -4. The time now is 12:18 AM.


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