Debian Codegraph @

recipes/haaretz_en.recipe

raw
1 # -*- mode: python; coding: utf-8; -*-
2 # vim: set syntax=python fileencoding=utf-8
3
4 __license__ = 'GPL v3'
5 __copyright__ = '2010-2022, Darko Miletic <darko.miletic at gmail.com>'
6 '''
7 www.haaretz.com
8 '''
9
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12 try:
13 from urllib.parse import urlencode
14 except ImportError:
15 from urllib import urlencode
16
17
18 class Haaretz_en(BasicNewsRecipe):
19 title = 'Haaretz'
20 __author__ = 'Darko Miletic'
21 description = "Haaretz.com is the world's leading English-language Website for real-time news and analysis of Israel and the Middle East."
22 publisher = 'Haaretz'
23 oldest_article = 2
24 max_articles_per_feed = 200
25 no_stylesheets = True
26 encoding = 'utf8'
27 use_embedded_content = False
28 language = 'en_IL'
29 needs_subscription = True
30 remove_empty_feeds = True
31 ignore_duplicate_articles = {'url'}
32 publication_type = 'newspaper'
33 PREFIX = 'https://www.haaretz.com'
34 LOGIN = 'https://services.haaretz.com/ms-sso/loginUrlEncoded'
35 LOGOUT = 'https://services.haaretz.com/ms-sso/logout'
36 extra_css = '''
37 body{font-family: Merriweather, "Helvetica Neue", Helvetica, Arial, sans-serif }
38 div.mx time{display: none}
39 div.my time{display: none}
40 div.mq time{display: none}
41 div.mr time{display: none}
42 '''
43
44 conversion_options = {'comment': description, 'publisher': publisher, 'language': language}
45
46 keep_only_tags = [
47 dict(name='div', attrs={'data-test': 'articleHeader'}),
48 dict(attrs={'data-test': 'articleBodyImage'}),
49 dict(name='div', attrs={'class': ['bu a b d e ', 'bu a b d e']}),
50 dict(name='div', attrs={'data-test': 'articleBody'}),
51 ]
52 remove_attributes = ['width', 'height']
53 remove_tags = [
54 dict(
55 name=['div', 'ul', 'button', 'svg'],
56 attrs={'data-test': ['audioPlayer', 'newsletter', 'relatedArticles', 'tags', 'writerAlertButton', 'IconAlefLogo']},
57 )
58 ]
59
60 feeds = [
61 ('Headlines', 'https://www.haaretz.com/srv/haaretz-latest-headlines'),
62 ('Opinion', 'https://www.haaretz.com/srv/opinion-rss'),
63 ('Security & Aviation', 'https://www.haaretz.com/srv/security-&-aviation-rss'),
64 ('Israel News', 'https://www.haaretz.com/srv/israel-news-rss'),
65 ('World News', 'https://www.haaretz.com/srv/world-news-rss'),
66 ('Jewish World', 'https://www.haaretz.com/srv/jewish-world-rss'),
67 ('Business', 'https://www.haaretz.com/srv/business-rss'),
68 ('Science & Health', 'https://www.haaretz.com/srv/science-&-health-rss'),
69 ('Life & Culture', 'https://www.haaretz.com/srv/life-&-culture-rss'),
70 ('Books', 'https://www.haaretz.com/srv/books-rss'),
71 ('Food', 'https://www.haaretz.com/srv/food-rss'),
72 ]
73
74 def get_browser(self):
75 br = BasicNewsRecipe.get_browser(self)
76 br.open(self.PREFIX)
77 if self.username is not None and self.password is not None:
78 data = urlencode({
79 'newsso': 'true',
80 'fromlogin': 'true',
81 'site': '85',
82 'layer': 'login',
83 'anonymousId': '16549476476914546',
84 'userName': self.username,
85 'password': self.password,
86 })
87 br.open(self.LOGIN, data)
88 return br