This commit is contained in:
Kovid Goyal 2023-09-08 12:02:20 +05:30
commit 3f217c9cb9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,6 +7,7 @@ usatoday.com
''' '''
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ptempfile import PersistentTemporaryFile
def classes(classes): def classes(classes):
@ -18,14 +19,14 @@ def classes(classes):
class USAToday(BasicNewsRecipe): class USAToday(BasicNewsRecipe):
title = 'USA Today' title = 'USA Today'
__author__ = 'Kovid Goyal' __author__ = 'Kovid Goyal, unkn0wn'
description = 'newspaper' description = 'newspaper'
encoding = 'utf-8' encoding = 'utf-8'
language = 'en' language = 'en'
use_embedded_content = False use_embedded_content = False
timefmt = ' [%d %b %Y]' timefmt = ' [%d %b %Y]'
max_articles_per_feed = 15 max_articles_per_feed = 25
no_stylesheets = True no_stylesheets = True
remove_empty_feeds = True remove_empty_feeds = True
@ -53,27 +54,54 @@ class USAToday(BasicNewsRecipe):
font-size:medium; font-size:medium;
font-family:Arial,Helvetica,sans-serif; font-family:Arial,Helvetica,sans-serif;
} }
.gnt_em_img_ccw__cap {
font-size:small;
text-align:center;
}
''' '''
feeds = [ ignore_duplicate_articles = {'title'}
('Top Headlines', resolve_internal_links = True
'http://rssfeeds.usatoday.com/usatoday-newstopstories&x=1'), remove_empty_feeds = True
('Tech Headlines',
'http://rssfeeds.usatoday.com/usatoday-techtopstories&x=1'), articles_are_obfuscated = True
('Personal Tech',
'http://rssfeeds.usatoday.com/usatodaycomtech-personaltalk&x=1'), def get_obfuscated_article(self, url):
('Health', br = self.get_browser()
'http://rssfeeds.usatoday.com/usatodaycomhealth-topstories&x=1'), try:
('Travel Headlines', br.open(url)
'http://rssfeeds.usatoday.com/usatodaycomtravel-topstories&x=1'), except Exception as e:
('Money Headlines', url = e.hdrs.get('location')
'http://rssfeeds.usatoday.com/usatodaycommoney-topstories&x=1'), soup = self.index_to_soup(url)
('Entertainment Headlines', link = soup.find('a', href=True)
'http://rssfeeds.usatoday.com/usatoday-lifetopstories&x=1'), skip_sections =[ # add sections you want to skip
('Sport Headlines', '/video/', '/videos/', '/media/', 'podcast-'
'http://rssfeeds.usatoday.com/usatodaycomsports-topstories&x=1'), ]
('Weather Headlines', if any(x in link['href'] for x in skip_sections):
'http://rssfeeds.usatoday.com/usatoday-weathertopstories&x=1'), self.log('Aborting Article ', link['href'])
('Most Popular', self.abort_article('skipping video links')
'http://rssfeeds.usatoday.com/usatoday-mostviewedarticles&x=1'),
self.log('Downloading ', link['href'])
html = br.open(link['href']).read()
pt = PersistentTemporaryFile('.html')
pt.write(html)
pt.close()
return pt.name
feeds = []
sections = [
'news', 'nation', 'politics', 'opinion', 'tech', 'entertainment', 'money', 'sports', 'travel', 'life', 'investigations',
] ]
for sec in sections:
a = 'https://news.google.com/rss/search?q=when:27h+allinurl:https%3A%2F%2Fwww.usatoday.com%2Fstory{}&hl=en-US&gl=US&ceid=US:en'
feeds.append((sec.capitalize(), a.format('%2F' + sec + '%2F')))
# feeds.append(('Others', a.format('')))
def preprocess_html(self, soup):
for img in soup.findAll('img', src=True):
img['src'] = 'https://www.usatoday.com' + img['src']
for div in soup.findAll(attrs={'data-c-caption':True}):
div.string = div['data-c-caption']
return soup