forked from ping/newsrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannelnewsasia.recipe.py
90 lines (79 loc) · 2.87 KB
/
channelnewsasia.recipe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (c) 2022 https://github.com/ping/
#
# This software is released under the GNU General Public License v3.0
# https://opensource.org/licenses/GPL-3.0
"""
channelnewsasia.com
"""
import os
import sys
# custom include to share code between recipes
sys.path.append(os.environ["recipes_includes"])
from recipes_shared import BasicNewsrackRecipe, format_title
from calibre.web.feeds.news import BasicNewsRecipe
_name = "ChannelNewsAsia"
class ChannelNewsAsia(BasicNewsrackRecipe, BasicNewsRecipe):
title = _name
__author__ = "ping"
description = "CNA: Breaking News, Singapore News, World and Asia https://www.channelnewsasia.com/"
publisher = "Mediacorp"
category = "news, Singapore"
publication_type = "newspaper"
language = "en"
masthead_url = "https://www.channelnewsasia.com/sites/default/themes/mc_cna_theme/images/logo.png"
oldest_article = 1
max_articles_per_feed = 25
remove_tags_before = [dict(class_=["h1--page-title"])]
remove_tags_after = [dict(class_=["content"])]
remove_attributes = ["style"]
remove_tags = [
dict(
class_=[
"js-popup-content",
"referenced-card",
"block--related-topics",
"block-ad-entity",
"block-block-content",
"from-library",
"block-field-blocknodearticlefield-author", # author bio
"mobile_author_card", # author bio
]
),
dict(name="div", attrs={"data-ad-entity": True}),
dict(name="div", attrs={"data-js-options": True}),
dict(name=["script", "noscript", "style", "svg"]),
]
extra_css = """
.figure__caption { font-size: 0.8rem; }
.figure__caption p { margin-top: 0.2rem; margin-bottom: 1rem; }
"""
feeds = [
# (
# "Latest News",
# "https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml",
# ),
(
"Singapore",
"https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml&category=10416",
),
(
"Asia",
"https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml&category=6511",
),
(
"Business",
"https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml&category=6936",
),
# (
# "Sport",
# "https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml&category=10296",
# ),
# (
# "World",
# "https://www.channelnewsasia.com/api/v1/rss-outbound-feed?_format=xml&category=6311",
# ),
]
def populate_article_metadata(self, article, __, _):
if (not self.pub_date) or article.utctime > self.pub_date:
self.pub_date = article.utctime
self.title = format_title(_name, article.utctime)