View Single Post
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