Debian Codegraph @

recipes/japan_times.recipe

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 __license__ = 'GPL v3'
5 __copyright__ = '2008-2013, Darko Miletic <darko.miletic at gmail.com>. 2022, Albert Aparicio Isarn <aaparicio at posteo.net>'
6 '''
7 japantimes.co.jp
8 '''
9
10 from calibre.web.feeds.news import BasicNewsRecipe
11
12
13 class JapanTimes(BasicNewsRecipe):
14 title = 'The Japan Times'
15 __author__ = 'Albert Aparicio Isarn (original recipe by Darko Miletic)'
16 description = "The latest news from Japan Times, Japan's leading English-language daily newspaper"
17 language = 'en_JP'
18 category = 'news, politics, japan'
19 publisher = 'The Japan Times'
20 oldest_article = 2
21 max_articles_per_feed = 150
22 no_stylesheets = True
23 remove_javascript = True
24 use_embedded_content = False
25 encoding = 'utf8'
26 publication_type = 'newspaper'
27 masthead_url = 'https://cdn-japantimes.com/wp-content/themes/jt_theme/library/img/japantimes-logo-tagline.png'
28 extra_css = 'body{font-family: Geneva,Arial,Helvetica,sans-serif}'
29
30 recipe_specific_options = {
31 'days': {
32 'short': 'Oldest article to download from this news source. In days ',
33 'long': 'For example, 0.5, gives you articles from the past 12 hours',
34 'default': str(oldest_article),
35 }
36 }
37
38 def __init__(self, *args, **kwargs):
39 BasicNewsRecipe.__init__(self, *args, **kwargs)
40 d = self.recipe_specific_options.get('days')
41 if d and isinstance(d, str):
42 self.oldest_article = float(d)
43
44 conversion_options = {
45 'comment': description,
46 'tags': category,
47 'publisher': publisher,
48 'language': language,
49 }
50
51 remove_tags_before = {'name': 'h1'}
52 remove_tags_after = {'name': 'ul', 'attrs': {'class': 'single-sns-area'}}
53 keep_only_tags = [
54 {'name': 'div', 'attrs': {'class': 'padding_block'}},
55 # {"name": "h5", "attrs": {"class": "writer", "role": "author"}},
56 # {"name": "p", "attrs": {"class": "credit"}},
57 ]
58 remove_tags = [
59 {'name': 'div', 'id': 'no_js_blocker', 'attrs': {'class': 'padding_block'}},
60 {'name': 'div', 'attrs': {'class': 'single-upper-meta'}},
61 {'name': 'ul', 'attrs': {'class': 'single-sns-area'}},
62 ]
63 feeds = [
64 ('Top Stories', 'https://www.japantimes.co.jp/feed/topstories/'),
65 ('News', 'https://www.japantimes.co.jp/news/feed/'),
66 ('Opinion', 'https://www.japantimes.co.jp/opinion/feed/'),
67 ('Life', 'https://www.japantimes.co.jp/life/feed/'),
68 ('Community', 'https://www.japantimes.co.jp/community/feed/'),
69 ('Culture', 'https://www.japantimes.co.jp/culture/feed/'),
70 ('Sports', 'https://www.japantimes.co.jp/sports/feed/'),
71 ]
72
73 def get_article_url(self, article):
74 rurl = BasicNewsRecipe.get_article_url(self, article)
75 return rurl.partition('?')[0]
76
77 def preprocess_raw_html(self, raw, url):
78 return '<html><head>' + raw[raw.find('</head>') :]