Merge branch 'appledaily-patch-20170123' of https://github.com/Kennyl/calibre

This commit is contained in:
Kovid Goyal 2017-01-23 21:21:04 +05:30
commit b581e6cef4

View File

@ -9,7 +9,6 @@ from calibre.utils.date import now as nowf
import os import os
import datetime import datetime
import re import re
import time
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
from contextlib import nested from contextlib import nested
from calibre.ebooks.BeautifulSoup import BeautifulSoup from calibre.ebooks.BeautifulSoup import BeautifulSoup
@ -34,7 +33,7 @@ class AppleDaily(BasicNewsRecipe):
no_stylesheets = True no_stylesheets = True
description = 'http://hkm.appledaily.com/' description = 'http://hkm.appledaily.com/'
category = 'Chinese, News, Hong Kong' category = 'Chinese, News, Hong Kong'
masthead_url = 'https://upload.wikimedia.org/wikipedia/zh/thumb/5/52/Apple_Daily_logo.svg/569px-Apple_Daily_logo.svg.png' masthead_url = 'https://upload.wikimedia.org/wikipedia/commons/8/86/Apple_Daily_Title.svg'
extra_css = 'img {display: block; margin-left: auto; margin-right: auto; margin-top: 10px; margin-bottom: 10px; max-height:90%;} h1 {font-size:200%; text-align:left; font-weight:bold;} p[class=video-caption] {font-size:50%; margin-left:auto; margin-right:auto;}' # noqa extra_css = 'img {display: block; margin-left: auto; margin-right: auto; margin-top: 10px; margin-bottom: 10px; max-height:90%;} h1 {font-size:200%; text-align:left; font-weight:bold;} p[class=video-caption] {font-size:50%; margin-left:auto; margin-right:auto;}' # noqa
keep_only_tags = [dict(name='div', attrs={'id': 'content-article'})] keep_only_tags = [dict(name='div', attrs={'id': 'content-article'})]
@ -105,16 +104,17 @@ class AppleDaily(BasicNewsRecipe):
relativea = li.find('a', href=True).get('href', False) relativea = li.find('a', href=True).get('href', False)
a = 'http://hkm.appledaily.com/' + relativea a = 'http://hkm.appledaily.com/' + relativea
title = li.find('a', text=True).strip() title = li.find('a', text=True).strip()
if (time.tzname != 'HKT'): # if (time.tzname != 'HKT'):
if (title == u'三藩市'): # if (title == u'三藩市'):
continue # continue
if (title == u'洛杉磯'): # if (title == u'洛杉磯'):
continue # continue
if (title == u'紐  約'): # if (title == u'紐  約'):
continue # continue
if (title == u'美  國'): # if (title == u'美  國'):
continue # continue
if (not title == u'動新聞') and (relativea.startswith('list.php')): # if (not title == u'動新聞') and (relativea.startswith('list.php')):
if (relativea.find('category=daily')!= -1)and (relativea.startswith('list.php')):
sectionList.append((title, a)) sectionList.append((title, a))
for title, url in sectionList: for title, url in sectionList:
title = title.replace(" ", "") title = title.replace(" ", "")
@ -262,8 +262,9 @@ class AppleDaily(BasicNewsRecipe):
not self.has_single_feed, not self.has_single_feed,
a.orig_url, __appname__, prefix=prefix, a.orig_url, __appname__, prefix=prefix,
center=self.center_navbar) center=self.center_navbar)
elem = BeautifulSoup(templ.render( translatedTempl =re.sub('<hr>.*<br><br>','<hr>從<a href="'+a.orig_url+'">蘋果日報</a>下載至'+__appname__+
doctype='xhtml').decode('utf-8')).find('div') '<br><br>',templ.render(doctype='xhtml').decode('utf-8'),flags=re.S)
elem = BeautifulSoup(translatedTempl).find('div')
body.insert(len(body.contents), elem) body.insert(len(body.contents), elem)
with open(last, 'wb') as fi: with open(last, 'wb') as fi:
fi.write(unicode(soup).encode('utf-8')) fi.write(unicode(soup).encode('utf-8'))