| 1 |
# vim:fileencoding=UTF-8 |
| 2 |
from __future__ import print_function, unicode_literals |
| 3 |
|
| 4 |
__license__ = 'GPL v3' |
| 5 |
__copyright__ = '2013, Eddie Lau' |
| 6 |
__Date__ = '' |
| 7 |
|
| 8 |
''' |
| 9 |
Change Log: |
| 10 |
2013/09/28 -- update due to website redesign, add cover |
| 11 |
2013/03/30 -- first version |
| 12 |
''' |
| 13 |
|
| 14 |
try: |
| 15 |
from urllib.parse import unquote |
| 16 |
except ImportError: |
| 17 |
from urllib import unquote |
| 18 |
|
| 19 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 20 |
|
| 21 |
|
| 22 |
class AM730(BasicNewsRecipe): |
| 23 |
title = 'AM730' |
| 24 |
__author__ = 'Eddie Lau' |
| 25 |
publisher = 'AM730' |
| 26 |
oldest_article = 1 |
| 27 |
max_articles_per_feed = 100 |
| 28 |
language = 'zh' |
| 29 |
encoding = 'utf-8' |
| 30 |
auto_cleanup = False |
| 31 |
remove_javascript = True |
| 32 |
use_embedded_content = False |
| 33 |
no_stylesheets = True |
| 34 |
description = 'http://www.am730.com.hk' |
| 35 |
category = 'Chinese, News, Hong Kong' |
| 36 |
masthead_url = 'https://upload.wikimedia.org/wikipedia/en/5/58/Am730_Hong_Kong_newspaper_logo.png' |
| 37 |
extra_css = 'img {display: block; margin-left: auto; margin-right: auto; margin-top: 20px; margin-bottom: 20px; max-height:70%;} div[id=articleHeader] {font-size:200%; text-align:left; font-weight:bold;} li {font-size:50%; margin-left:auto; margin-right:auto;}' # noqa: E501 |
| 38 |
remove_tags = [ |
| 39 |
dict(name='div', attrs={'class': 'col-xs-12 col-sm-1 col-md-1 share-button'}), |
| 40 |
dict(name='div', attrs={'class': 'logo-container print-logo'}), |
| 41 |
dict(name='div', attrs={'id': 'galleria'}), |
| 42 |
] |
| 43 |
keep_only_tags = [ |
| 44 |
dict(name='div', attrs={'class': 'col-xs-12 col-sm-12 col-md-12 news-detail-content-container'}), |
| 45 |
# dict(name='div',attrs={'class':'columns-left'})] |
| 46 |
] |
| 47 |
compress_news_images = True |
| 48 |
compress_news_images_auto_size = 16 |
| 49 |
compress_news_images_max_size = 20 # kB |
| 50 |
scale_news_images = (600, 800) |
| 51 |
ignore_duplicate_articles = {'title', 'url'} |
| 52 |
|
| 53 |
debug = False |
| 54 |
|
| 55 |
def get_cover_url(self): |
| 56 |
return self.masthead_url |
| 57 |
|
| 58 |
def getAMSectionArticles(self, sectionName, url): |
| 59 |
# print(sectionName) |
| 60 |
soup = self.index_to_soup(url) |
| 61 |
articles = [] |
| 62 |
for aTag in soup.findAll('a', attrs={'class': 'newsimglink'}): |
| 63 |
href = aTag.get('href', False) |
| 64 |
if not href.encode('utf-8').startswith(url.encode('utf-8')): |
| 65 |
continue # not in same section |
| 66 |
|
| 67 |
title = href.split('/')[-1].split('-')[0] |
| 68 |
title = unquote(title.encode('ASCII')) # .decode('utf-8') |
| 69 |
if self.debug: |
| 70 |
print(title) |
| 71 |
try: |
| 72 |
if articles.index({'title': title, 'url': href}) >= 0: |
| 73 |
# print('already added') |
| 74 |
continue # already added |
| 75 |
except Exception: |
| 76 |
pass |
| 77 |
|
| 78 |
articles.append({'title': title, 'url': href}) |
| 79 |
|
| 80 |
if len(articles) >= self.max_articles_per_feed: |
| 81 |
break |
| 82 |
if self.debug: |
| 83 |
print(articles) |
| 84 |
return sectionName, articles |
| 85 |
|
| 86 |
def parse_index(self): |
| 87 |
# hard code sections |
| 88 |
Sections = [ |
| 89 |
('新聞', 'https://www.am730.com.hk/news/%E6%96%B0%E8%81%9E'), |
| 90 |
('財經', 'https://www.am730.com.hk/news/%E8%B2%A1%E7%B6%93'), |
| 91 |
('健康', 'https://www.am730.com.hk/news/%E5%81%A5%E5%BA%B7'), |
| 92 |
('科技', 'https://www.am730.com.hk/news/%E7%A7%91%E6%8A%80'), |
| 93 |
('體育', 'https://www.am730.com.hk/news/%E9%AB%94%E8%82%B2'), |
| 94 |
('娛樂', 'https://www.am730.com.hk/news/%E5%A8%9B%E6%A8%82'), |
| 95 |
('旅遊.飲食', 'https://www.am730.com.hk/news/%E6%97%85%E9%81%8A.%E9%A3%B2%E9%A3%9F'), |
| 96 |
] # articles =[] |
| 97 |
SectionsArticles = [] |
| 98 |
for title, url in Sections: |
| 99 |
if self.debug: |
| 100 |
print(title) |
| 101 |
print(url) |
| 102 |
SectionsArticles.append(self.getAMSectionArticles(title, url)) |
| 103 |
# feeds.append(articles[0]['url']) |
| 104 |
return SectionsArticles |