mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-29 15:31:08 -04:00
65 lines
2.6 KiB
Python
65 lines
2.6 KiB
Python
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
|
|
|
|
|
class STHKRecipe(BasicNewsRecipe):
|
|
title = '星島日報 (香港)'
|
|
__author__ = 'unkn0wn'
|
|
description = 'The Sing Tao Daily is among Hong Kong\'s oldest Chinese language newspapers. (https://std.stheadline.com/)'
|
|
category = 'Chinese, News, Hong Kong'
|
|
language = 'zh'
|
|
encoding = 'utf-8'
|
|
masthead_url = 'https://std.stheadline.com/dist/images/logo-v2@2x.png'
|
|
no_stylesheets = True
|
|
remove_javascript = True
|
|
ignore_duplicate_articles = {'title'}
|
|
remove_empty_feeds = True
|
|
use_embedded_content = False
|
|
remove_attributes = ['style', 'height', 'width']
|
|
|
|
extra_css = '''
|
|
img {display:block; margin:0 auto;}
|
|
.date { font-size:small; }
|
|
.caption-text, .media-library-item__attributes { font-size:small; text-align:center; }
|
|
'''
|
|
|
|
keep_only_tags = [
|
|
dict(name='article', attrs={'class':'content'})
|
|
]
|
|
remove_tags = [
|
|
dict(name=['video', 'svg', 'button']),
|
|
dict(attrs={'id':'articleShareIcons'}),
|
|
classes('in-article-banner stick-box-gray article-pagination comments')
|
|
]
|
|
|
|
articles_are_obfuscated = True
|
|
|
|
def get_obfuscated_article(self, url):
|
|
br = self.get_browser()
|
|
try:
|
|
br.open(url)
|
|
except Exception as e:
|
|
url = e.hdrs.get('location')
|
|
soup = self.index_to_soup(url)
|
|
link = soup.find('a', href=True)['href']
|
|
skip_sections = [ # add sections you want to skip
|
|
'/video/', '/videos/', '/media/', 'podcast'
|
|
]
|
|
if any(x in link for x in skip_sections):
|
|
self.log('Aborting Article ', link)
|
|
self.abort_article('skipping video links')
|
|
html = br.open(link).read()
|
|
return ({ 'data': html, 'url': link })
|
|
|
|
feeds = [
|
|
('日報', 'https://news.google.com/rss/search?q=when:27h+allinurl:https%3A%2F%2Fstd.stheadline.com%2Fdaily%2F&hl=zh-HK&gl=HK&ceid=HK:zh'),
|
|
('即時', 'https://news.google.com/rss/search?q=when:27h+allinurl:https%3A%2F%2Fstd.stheadline.com%2Frealtime%2F&hl=zh-HK&gl=HK&ceid=HK:zh'),
|
|
('副刊', 'https://news.google.com/rss/search?q=when:27h+allinurl:https%3A%2F%2Fstd.stheadline.com%2Fsupplement%2F&hl=zh-HK&gl=HK&ceid=HK:zh'),
|
|
('其他的 新聞', 'https://news.google.com/rss/search?q=when:27h+allinurl:https%3A%2F%2Fstd.stheadline.com&hl=zh-HK&gl=HK&ceid=HK:zh')
|
|
]
|
|
|
|
def populate_article_metadata(self, article, soup, first):
|
|
article.title = article.title.replace(' - 星島頭條', '')
|
|
|
|
def preprocess_raw_html(self, raw, *a):
|
|
return raw.replace('<p></p>', '')
|