From 95b2e521c470c95b3461e9969af708ffad1acd00 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 31 Aug 2022 20:45:21 +0530 Subject: [PATCH] Update Financial Times --- recipes/financial_times.recipe | 24 ++++++++++++++------ recipes/financial_times_print_edition.recipe | 24 ++++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/recipes/financial_times.recipe b/recipes/financial_times.recipe index 6d0df16df3..15eec6dea8 100644 --- a/recipes/financial_times.recipe +++ b/recipes/financial_times.recipe @@ -21,13 +21,23 @@ class ft(BasicNewsRecipe): extra_css = '#fig-cap{font-style:italic; text-align:left; font-size:small;}' def get_cover_url(self): - soup = self.index_to_soup( - 'https://www.todayspapers.co.uk/the-financial-times-front-page-today/' - ) - tag = soup.find('div', attrs={'class': 'elementor-image'}) - if tag: - self.cover_url = tag.find('img')['src'] - return getattr(self, 'cover_url', self.cover_url) + from datetime import date + cover = 'http://img.kiosko.net/' + str( + date.today().year + ) + '/' + date.today().strftime('%m') + '/' + date.today( + ).strftime('%d') + '/uk/ft_uk.750.jpg' + br = BasicNewsRecipe.get_browser(self) + try: + br.open(cover) + except: + index = 'https://en.kiosko.net/uk/np/ft_uk.html' + soup = self.index_to_soup(index) + 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 feeds = [ ('World', 'https://www.ft.com/world?format=rss'), diff --git a/recipes/financial_times_print_edition.recipe b/recipes/financial_times_print_edition.recipe index a26d1e4889..ec357bb0a9 100644 --- a/recipes/financial_times_print_edition.recipe +++ b/recipes/financial_times_print_edition.recipe @@ -19,13 +19,23 @@ class ft(BasicNewsRecipe): extra_css = '#fig-cap{font-style:italic; text-align:left; font-size:small;}' def get_cover_url(self): - soup = self.index_to_soup( - 'https://www.todayspapers.co.uk/the-financial-times-front-page-today/' - ) - tag = soup.find('div', attrs={'class': 'elementor-image'}) - if tag: - self.cover_url = tag.find('img')['src'] - return getattr(self, 'cover_url', self.cover_url) + from datetime import date + cover = 'http://img.kiosko.net/' + str( + date.today().year + ) + '/' + date.today().strftime('%m') + '/' + date.today( + ).strftime('%d') + '/uk/ft_uk.750.jpg' + br = BasicNewsRecipe.get_browser(self) + try: + br.open(cover) + except: + index = 'https://en.kiosko.net/uk/np/ft_uk.html' + soup = self.index_to_soup(index) + 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 def parse_index(self): soup = self.index_to_soup('https://www.ft.com/todaysnewspaper/uk')