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 02-08-2020, 06:38 AM   #1
pacha2
Member
pacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
pacha2's Avatar
 
Posts: 18
Karma: 12710
Join Date: Feb 2020
Device: Kindle Paperwhite
Help adding cover_image code

I have some code that retrieves a cover image for The Guardian, it runs in Jupyter but I can't translate it to a recipe.
I copied the code snippets here, but it doesn't work for me. Maybe that post is outdated?
https://www.mobileread.com/forums/sh...53&postcount=5

Here's my working python from Jupyter
Code:
    from urllib.request import urlopen
    from bs4 import BeautifulSoup
    from datetime import date, datetime, timedelta
    basedate = date.today() - timedelta(days=2)
    baseurl = 'https://mobile.twitter.com/search?q=Guardian%20front%20page%20%20%28from%3AGuardian%29%20since%3A' + str(basedate)
    data = str(urlopen(baseurl).read())
    html = BeautifulSoup(data, 'html.parser')
    media=html.find(class_="media")
    img = media.find('img')
    cover_url=img.get('src')
And here is the snippet of my attempt at making that work in function in a recipe.
Code:
 def get_cover_img_url(self):
        basedate = date.today() - timedelta(days=2)
        baseurl = 'https://mobile.twitter.com/search?q=Guardian%20front%20page%20%20%28from%3AGuardian%29%20since%3A' + str(basedate)
        html=self.index_to_soup(baseurl)
        media=html.find(class_="media")
        img = media.find('img')
        cover_img_url=img.get('src')
        return getattr(self, 'cover_img_url', None)
When executing the recipe the end of log shows

Code:
  File "site-packages/calibre/web/feeds/news.py", line 1617, in parse_feeds
  File "site-packages/calibre/web/feeds/news.py", line 447, in get_feeds
NotImplementedError
Any help would be greatly appreciated.
pacha2 is offline   Reply With Quote
Old 02-08-2020, 07:18 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,910
Karma: 22669818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
that error is because you dont have either a parse_index method or feeds defined in your recipe.
kovidgoyal is offline   Reply With Quote
Old 02-09-2020, 03:41 PM   #3
pacha2
Member
pacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameterpacha2 can solve quadratic equations while standing on his or her head reciting poetry in iambic pentameter
 
pacha2's Avatar
 
Posts: 18
Karma: 12710
Join Date: Feb 2020
Device: Kindle Paperwhite
Thanks for the reply. I did have those, but the old import seem to break the standard recipe.
The old code snippets I copied and pasted seemed to cause more issue for me.

I the code working now, and I have pasted it below.
I modified the
It grabs the latest paper front page for either The Guardian and The Observer.

Code:
import urllib2
from datetime import date, timedelta
from bs4 import BeautifulSoup

def twitter_front_page():
        basedate = date.today() - timedelta(days=2)
        baseurl = 'https://mobile.twitter.com/search?q=front%20page%20%20%28from%3Aobserveruk%20OR%20from%3Aguardian%29%20since%3A' + str(basedate)
        data = urllib2.urlopen(baseurl)
        html = BeautifulSoup(data, 'html.parser')
        media = html.find(class_="media")
        img = media.find('img')
        twitter_cover = img.get('src') 
        return twitter_cover

    cover_url = twitter_front_page()
pacha2 is offline   Reply With Quote
Reply

Tags
cover_img_url, recipe


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
After I Edit Code, Save, and Convert, all my Code Edits are Gone lukewrussell Calibre 1 03-14-2014 08:05 PM
Sigil Automatically Adding Code christinerose Sigil 7 04-28-2011 11:07 AM
code help AWOL Sigil 7 11-19-2010 11:50 AM
Let's create a source code repository for DR 800 related code? jraf iRex 3 03-11-2010 12:26 PM
Hi all — and see the code sigizmund Introduce Yourself 2 12-18-2009 02:53 AM


All times are GMT -4. The time now is 01:58 PM.


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