|
|
#1 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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')
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)
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 |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,627
Karma: 28549046
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.
|
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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()
|
|
|
|
![]() |
| Tags |
| cover_img_url, recipe |
|
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 09:05 PM |
| Sigil Automatically Adding Code | christinerose | Sigil | 7 | 04-28-2011 12:07 PM |
| code help | AWOL | Sigil | 7 | 11-19-2010 12:50 PM |
| Let's create a source code repository for DR 800 related code? | jraf | iRex | 3 | 03-11-2010 01:26 PM |
| Hi all — and see the code | sigizmund | Introduce Yourself | 2 | 12-18-2009 03:53 AM |