| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
__license__ = 'GPL v3' |
| 5 |
__copyright__ = '2022, Albert Aparicio Isarn <aaparicio at posteo.net>' |
| 6 |
|
| 7 |
''' |
| 8 |
https://www.asahi.com/ajw/ |
| 9 |
''' |
| 10 |
|
| 11 |
from datetime import datetime |
| 12 |
|
| 13 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 14 |
|
| 15 |
|
| 16 |
class AsahiShimbunEnglishNews(BasicNewsRecipe): |
| 17 |
title = 'The Asahi Shimbun' |
| 18 |
__author__ = 'Albert Aparicio Isarn' |
| 19 |
|
| 20 |
description = ( |
| 21 |
'The Asahi Shimbun is widely regarded for its journalism as the most respected daily newspaper in Japan.' |
| 22 |
' The English version offers selected articles from the vernacular Asahi Shimbun, as well as extensive' |
| 23 |
' coverage of cool Japan,focusing on manga, travel and other timely news.' |
| 24 |
) |
| 25 |
publisher = 'The Asahi Shimbun Company' |
| 26 |
publication_type = 'newspaper' |
| 27 |
category = 'news, japan' |
| 28 |
language = 'en_JP' |
| 29 |
|
| 30 |
index = 'https://www.asahi.com' |
| 31 |
masthead_url = 'https://p.potaufeu.asahi.com/ajw/css/images/[email protected]' |
| 32 |
|
| 33 |
oldest_article = 3 |
| 34 |
max_articles_per_feed = 40 |
| 35 |
no_stylesheets = True |
| 36 |
remove_javascript = True |
| 37 |
|
| 38 |
remove_tags_before = {'id': 'MainInner'} |
| 39 |
remove_tags_after = {'class': 'ArticleText'} |
| 40 |
remove_tags = [{'name': 'div', 'class': 'SnsUtilityArea'}] |
| 41 |
|
| 42 |
def get_whats_new(self): |
| 43 |
soup = self.index_to_soup(self.index + '/ajw/new') |
| 44 |
news_section = soup.find('div', attrs={'class': 'specialList'}) |
| 45 |
|
| 46 |
new_news = [] |
| 47 |
|
| 48 |
for item in news_section.findAll('li'): |
| 49 |
title = item.find('p', attrs={'class': 'title'}).string |
| 50 |
date_string = item.find('p', attrs={'class': 'date'}).next |
| 51 |
date = date_string.strip() |
| 52 |
url = self.index + item.find('a')['href'] |
| 53 |
|
| 54 |
new_news.append({ |
| 55 |
'title': title, |
| 56 |
'date': datetime.strptime(date, '%B %d, %Y').strftime('%Y/%m/%d'), |
| 57 |
'url': url, |
| 58 |
'description': '', |
| 59 |
}) |
| 60 |
|
| 61 |
return new_news |
| 62 |
|
| 63 |
def get_top6(self, soup): |
| 64 |
top = soup.find('ul', attrs={'class': 'top6'}) |
| 65 |
|
| 66 |
top6_news = [] |
| 67 |
|
| 68 |
for item in top.findAll('li'): |
| 69 |
title = item.find('p', attrs={'class': 'title'}).string |
| 70 |
date_string = item.find('p', attrs={'class': 'date'}).next |
| 71 |
date = date_string.strip() |
| 72 |
url = self.index + item.find('a')['href'] |
| 73 |
|
| 74 |
top6_news.append({ |
| 75 |
'title': title, |
| 76 |
'date': datetime.strptime(date, '%B %d, %Y').strftime('%Y/%m/%d'), |
| 77 |
'url': url, |
| 78 |
'description': '', |
| 79 |
}) |
| 80 |
|
| 81 |
return top6_news |
| 82 |
|
| 83 |
def get_section_news(self, soup): |
| 84 |
news_grid = soup.find('ul', attrs={'class': 'default'}) |
| 85 |
|
| 86 |
news = [] |
| 87 |
|
| 88 |
for item in news_grid.findAll('li'): |
| 89 |
title = item.find('p', attrs={'class': 'title'}).string |
| 90 |
date_string = item.find('p', attrs={'class': 'date'}).next |
| 91 |
date = date_string.strip() |
| 92 |
|
| 93 |
url = self.index + item.find('a')['href'] |
| 94 |
|
| 95 |
news.append({ |
| 96 |
'title': title, |
| 97 |
'date': datetime.strptime(date, '%B %d, %Y').strftime('%Y/%m/%d'), |
| 98 |
'url': url, |
| 99 |
'description': '', |
| 100 |
}) |
| 101 |
|
| 102 |
return news |
| 103 |
|
| 104 |
def get_section(self, section): |
| 105 |
soup = self.index_to_soup(self.index + '/ajw/' + section) |
| 106 |
|
| 107 |
section_news_items = self.get_top6(soup) |
| 108 |
section_news_items.extend(self.get_section_news(soup)) |
| 109 |
|
| 110 |
return section_news_items |
| 111 |
|
| 112 |
def get_special_section(self, section): |
| 113 |
soup = self.index_to_soup(self.index + '/ajw/' + section) |
| 114 |
top = soup.find('div', attrs={'class': 'Section'}) |
| 115 |
|
| 116 |
special_news = [] |
| 117 |
|
| 118 |
for item in top.findAll('li'): |
| 119 |
item_a = item.find('a') |
| 120 |
|
| 121 |
text_split = item_a.text.strip().split('\n') |
| 122 |
title = text_split[0] |
| 123 |
description = text_split[1].strip() |
| 124 |
|
| 125 |
url = self.index + item_a['href'] |
| 126 |
|
| 127 |
special_news.append({ |
| 128 |
'title': title, |
| 129 |
'date': '', |
| 130 |
'url': url, |
| 131 |
'description': description, |
| 132 |
}) |
| 133 |
|
| 134 |
return special_news |
| 135 |
|
| 136 |
def parse_index(self): |
| 137 |
# soup = self.index_to_soup(self.index) |
| 138 |
|
| 139 |
feeds = [ |
| 140 |
("What's New", self.get_whats_new()), |
| 141 |
('National Report', self.get_section('national_report')), |
| 142 |
('Politics', self.get_section('politics')), |
| 143 |
('Business', self.get_section('business')), |
| 144 |
('Asia & World - China', self.get_section('asia_world/china')), |
| 145 |
('Asia & World - Korean Peninsula', self.get_section('asia_world/korean_peninsula')), |
| 146 |
('Asia & World - Around Asia', self.get_section('asia_world/around_asia')), |
| 147 |
('Asia & World - World', self.get_section('asia_world/world')), |
| 148 |
('Sci & Tech', self.get_section('sci_tech')), |
| 149 |
('Culture - Style', self.get_section('culture/style')), |
| 150 |
# ("Culture - Cooking", self.get_section("culture/cooking")), |
| 151 |
('Culture - Movies', self.get_section('culture/movies')), |
| 152 |
('Culture - Manga & Anime', self.get_section('culture/manga_anime')), |
| 153 |
('Travel', self.get_section('travel')), |
| 154 |
('Sports', self.get_section('sports')), |
| 155 |
('Opinion - Editorial', self.get_section('opinion/editorial')), |
| 156 |
('Opinion - Vox Populi', self.get_section('opinion/vox')), |
| 157 |
('Opinion - Views', self.get_section('opinion/views')), |
| 158 |
# ('Special', self.get_special_section('special')), |
| 159 |
] |
| 160 |
|
| 161 |
return feeds |