mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get a past edition (e.g., date='2020-11-28').
A new function edition(date) allows the user to specify a past edition. The default, date='', takes the current edition. The proper cover URL appears in the Calibre desktop app, though not on Kindle Oasis - a minor remaining issue. Much respect and admiration for Kovid Goyal's work.
This commit is contained in:
parent
744278b819
commit
526969213c
@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from http.cookiejar import Cookie
|
from http.cookiejar import Cookie
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -15,6 +17,14 @@ from calibre.ebooks.BeautifulSoup import NavigableString, Tag
|
|||||||
from calibre.utils.cleantext import clean_ascii_chars
|
from calibre.utils.cleantext import clean_ascii_chars
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
|
def edition(date=''):
|
||||||
|
""" For past editions, set date to, for example, '2020-11-28'. """
|
||||||
|
title = 'The Economist'
|
||||||
|
INDEX = 'https://www.economist.com/weeklyedition'
|
||||||
|
if date:
|
||||||
|
title += ' ' + date
|
||||||
|
INDEX += '/' + date
|
||||||
|
return title, INDEX
|
||||||
|
|
||||||
def E(parent, name, text='', **attrs):
|
def E(parent, name, text='', **attrs):
|
||||||
ans = parent.makeelement(name, **attrs)
|
ans = parent.makeelement(name, **attrs)
|
||||||
@ -90,11 +100,10 @@ def process_url(url):
|
|||||||
|
|
||||||
class Economist(BasicNewsRecipe):
|
class Economist(BasicNewsRecipe):
|
||||||
|
|
||||||
title = 'The Economist'
|
title, INDEX = edition()
|
||||||
language = 'en'
|
language = 'en'
|
||||||
|
|
||||||
__author__ = "Kovid Goyal"
|
__author__ = "Kovid Goyal"
|
||||||
INDEX = 'https://www.economist.com/printedition'
|
|
||||||
description = (
|
description = (
|
||||||
'Global news and current affairs from a European'
|
'Global news and current affairs from a European'
|
||||||
' perspective. Best downloaded on Friday mornings (GMT)'
|
' perspective. Best downloaded on Friday mornings (GMT)'
|
||||||
@ -249,13 +258,21 @@ class Economist(BasicNewsRecipe):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def economist_parse_index(self, soup):
|
def economist_parse_index(self, soup):
|
||||||
archive = self.index_to_soup("https://www.economist.com/weeklyedition/archive")
|
if self.INDEX.endswith('weeklyedition'):
|
||||||
div = archive.find(attrs={'class': 'edition-teaser__image'})
|
archive = self.index_to_soup("https://www.economist.com/weeklyedition/archive")
|
||||||
if div is not None:
|
div = archive.find(attrs={'class': 'edition-teaser__image'})
|
||||||
img = div.find('img', srcset=True)
|
if div is not None:
|
||||||
self.cover_url = img['srcset'].split(',')[-1].split()[0]
|
img = div.find('img', srcset=True)
|
||||||
self.log('Got cover:', self.cover_url)
|
self.cover_url = img['srcset'].split(',')[-1].split()[0]
|
||||||
|
self.log('Got cover:', self.cover_url)
|
||||||
|
else:
|
||||||
|
date8 = self.INDEX[-10:].replace('-', '')
|
||||||
|
resource = urllib.request.urlopen("https://www.economist.com/weeklyedition/archive?year={}".format(date8[:4]))
|
||||||
|
archive = resource.read().decode(resource.headers.get_content_charset())
|
||||||
|
if date8 in archive:
|
||||||
|
parts = archive.split(date8)
|
||||||
|
self.cover_url = parts[-3].split(',')[-1]+date8+parts[-2].split()[0]
|
||||||
|
self.log('Got cover:', self.cover_url)
|
||||||
feeds = []
|
feeds = []
|
||||||
for section in soup.findAll(**classes('layout-weekly-edition-section')):
|
for section in soup.findAll(**classes('layout-weekly-edition-section')):
|
||||||
h2 = section.find('h2')
|
h2 = section.find('h2')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user