mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
More robust cover download source
This commit is contained in:
parent
467d35d1d0
commit
3c0ab1cdee
@ -47,19 +47,23 @@ class TimesOnline(BasicNewsRecipe):
|
|||||||
|
|
||||||
def get_cover_url(self):
|
def get_cover_url(self):
|
||||||
from datetime import date
|
from datetime import date
|
||||||
cover = 'http://img.kiosko.net/' + str(
|
from datetime import timedelta
|
||||||
date.today().year) + '/' + date.today().strftime('%m') + '/' + date.today().strftime('%d') + '/uk/the_times.750.jpg'
|
today = date.today()
|
||||||
|
today_index = today.weekday()
|
||||||
|
if (today_index == 6): # Special cover on Sundays
|
||||||
|
cover = 'https://cdn2-img.pressreader.com/pressdisplay/docserver/getimage.aspx?file=1163' + today.strftime('%Y') + today.strftime('%m') + today.strftime('%d') + '00000000001001&page=1&scale=99'
|
||||||
|
altcover = 'https://cdn2-img.pressreader.com/pressdisplay/docserver/getimage.aspx?file=1163' + today.strftime('%Y') + today.strftime('%m') + today.strftime('%d') + '00000051001001&page=1&scale=99'
|
||||||
|
# on some days cover is iterated using format here for altcover
|
||||||
|
else: # Mon-Thurs
|
||||||
|
cover = 'https://cdn2-img.pressreader.com/pressdisplay/docserver/getimage.aspx?file=1148' + today.strftime('%Y') + today.strftime('%m') + today.strftime('%d') + '00000000001001&page=1&scale=99'
|
||||||
|
altcover = 'https://cdn2-img.pressreader.com/pressdisplay/docserver/getimage.aspx?file=1148' + today.strftime('%Y') + today.strftime('%m') + today.strftime('%d') + '00000051001001&page=1&scale=99'
|
||||||
|
self.log(cover)
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
try:
|
try:
|
||||||
br.open(cover)
|
br.open(cover)
|
||||||
except:
|
except:
|
||||||
index = 'http://en.kiosko.net/uk/np/the_times.html'
|
cover = altcover
|
||||||
soup = self.index_to_soup(index)
|
br.open(cover)
|
||||||
for image in soup.findAll('img', src=True):
|
|
||||||
if image['src'].endswith('750.jpg'):
|
|
||||||
return image['src']
|
|
||||||
self.log("\nCover unavailable")
|
|
||||||
cover = None
|
|
||||||
return cover
|
return cover
|
||||||
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user