mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update economist_news.recipe
add options
This commit is contained in:
parent
34a5b05df4
commit
a8c6817613
@ -139,7 +139,7 @@ class EconomistNews(BasicNewsRecipe):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
cover_url = 'https://yt3.googleusercontent.com/UnUx7LD3mPISiPJo76CrN7vIUPAS4ATbVIBm3H76KWzCkNJeqMqJC0gpY6ArJfQBKQ2w7sQ5WQ=s0'
|
cover_url = 'https://yt3.googleusercontent.com/UnUx7LD3mPISiPJo76CrN7vIUPAS4ATbVIBm3H76KWzCkNJeqMqJC0gpY6ArJfQBKQ2w7sQ5WQ=s0'
|
||||||
oldest_article = 7.0
|
oldest_article = 15
|
||||||
resolve_internal_links = True
|
resolve_internal_links = True
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
dict(name=['script', 'noscript', 'title', 'iframe', 'cf_floatingcontent', 'aside', 'footer', 'svg']),
|
dict(name=['script', 'noscript', 'title', 'iframe', 'cf_floatingcontent', 'aside', 'footer', 'svg']),
|
||||||
@ -175,6 +175,25 @@ class EconomistNews(BasicNewsRecipe):
|
|||||||
|
|
||||||
needs_subscription = False
|
needs_subscription = False
|
||||||
|
|
||||||
|
recipe_specific_options = {
|
||||||
|
'days': {
|
||||||
|
'short': 'Oldest article to download from this news source. In days ',
|
||||||
|
'long': 'For example, 0.5, gives you articles from the past 12 hours',
|
||||||
|
'default': str(oldest_article)
|
||||||
|
},
|
||||||
|
'res': {
|
||||||
|
'short': 'For hi-res images, select a resolution from the\nfollowing options: 834, 960, 1096, 1280, 1424',
|
||||||
|
'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use from 480, 384, 360, 256.',
|
||||||
|
'default': '600',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
BasicNewsRecipe.__init__(self, *args, **kwargs)
|
||||||
|
d = self.recipe_specific_options.get('days')
|
||||||
|
if d and isinstance(d, str):
|
||||||
|
self.oldest_article = float(d)
|
||||||
|
|
||||||
def get_browser(self, *args, **kwargs):
|
def get_browser(self, *args, **kwargs):
|
||||||
# Needed to bypass cloudflare
|
# Needed to bypass cloudflare
|
||||||
kwargs['user_agent'] = 'common_words/based'
|
kwargs['user_agent'] = 'common_words/based'
|
||||||
@ -226,6 +245,10 @@ class EconomistNews(BasicNewsRecipe):
|
|||||||
desc = sub + ' :: ' + desc
|
desc = sub + ' :: ' + desc
|
||||||
if not art.get('text'):
|
if not art.get('text'):
|
||||||
continue
|
continue
|
||||||
|
date_ = art['datePublished']
|
||||||
|
dt = datetime.fromisoformat(date_[:-1]) + timedelta(seconds=time.timezone)
|
||||||
|
if (datetime.now() - dt) > timedelta(self.oldest_article):
|
||||||
|
continue
|
||||||
pt = PersistentTemporaryFile('.html')
|
pt = PersistentTemporaryFile('.html')
|
||||||
pt.write(json.dumps(art).encode('utf-8'))
|
pt.write(json.dumps(art).encode('utf-8'))
|
||||||
pt.close()
|
pt.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user