From e05dedfa0ff4c3d79c241cb19c7ed1c7a2fe45a2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 1 Jul 2010 08:46:53 -0600 Subject: [PATCH] ifzm by rty. Fixes #6043 (Wrong Chinese Category in News) --- resources/recipes/china_press.recipe | 2 +- resources/recipes/ifzm.recipe | 50 +++++++++++++++++++++++++++ src/calibre/devices/apple/driver.py | 3 +- src/calibre/ebooks/metadata/covers.py | 15 ++++++++ src/calibre/web/feeds/templates.py | 2 +- 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 resources/recipes/ifzm.recipe create mode 100644 src/calibre/ebooks/metadata/covers.py diff --git a/resources/recipes/china_press.recipe b/resources/recipes/china_press.recipe index 9ceea1a423..502ebfd41c 100644 --- a/resources/recipes/china_press.recipe +++ b/resources/recipes/china_press.recipe @@ -7,7 +7,7 @@ class AdvancedUserRecipe1277228948(BasicNewsRecipe): __author__ = 'rty' __version__ = '1.0' - language = 'zh_CN' + language = 'zh' pubisher = 'www.chinapressusa.com' description = 'Overseas Chinese Network Newspaper in the USA' category = 'News in Chinese, USA' diff --git a/resources/recipes/ifzm.recipe b/resources/recipes/ifzm.recipe new file mode 100644 index 0000000000..407acefdd4 --- /dev/null +++ b/resources/recipes/ifzm.recipe @@ -0,0 +1,50 @@ +from calibre.web.feeds.news import BasicNewsRecipe + +class AdvancedUserRecipe1277305250(BasicNewsRecipe): + title = u'infzm - China Southern Weekly' + oldest_article = 14 + max_articles_per_feed = 100 + + feeds = [(u'\u5357\u65b9\u5468\u672b-\u70ed\u70b9\u65b0\u95fb', u'http://www.infzm.com/rss/home/rss2.0.xml'), + (u'\u5357\u65b9\u5468\u672b-\u7ecf\u6d4e\u65b0\u95fb', u'http://www.infzm.com/rss/economic.xml'), + (u'\u5357\u65b9\u5468\u672b-\u6587\u5316\u65b0\u95fb', u'http://www.infzm.com/rss/culture.xml'), + (u'\u5357\u65b9\u5468\u672b-\u751f\u6d3b\u65f6\u5c1a', u'http://www.infzm.com/rss/lifestyle.xml'), + (u'\u5357\u65b9\u5468\u672b-\u89c2\u70b9', u'http://www.infzm.com/rss/opinion.xml') + ] + __author__ = 'rty' + __version__ = '1.0' + language = 'zh' + pubisher = 'http://www.infzm.com' + description = 'Chinese Weekly Tabloid' + category = 'News, China' + remove_javascript = True + use_embedded_content = False + no_stylesheets = True + #encoding = 'GB2312' + encoding = 'UTF-8' + conversion_options = {'linearize_tables':True} + masthead_url = 'http://i50.tinypic.com/2qmfb7l.jpg' + + extra_css = ''' + @font-face { font-family: "DroidFont", serif, sans-serif; src: url(res:///system/fonts/DroidSansFallback.ttf); }\n + body { + margin-right: 8pt; + font-family: 'DroidFont', serif;} + .detailContent {font-family: 'DroidFont', serif, sans-serif} + ''' + + keep_only_tags = [ + dict(name='div', attrs={'id':'detailContent'}), + ] + remove_tags = [ + dict(name='div', attrs={'id':['detailTools', 'detailSideL', 'pageNum']}), + ] + remove_tags_after = [ + dict(name='div', attrs={'id':'pageNum'}), + ] + def preprocess_html(self, soup): + for item in soup.findAll(color=True): + del item['font'] + for item in soup.findAll(style=True): + del item['style'] + return soup diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 9028347c4b..3156542a92 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -20,7 +20,7 @@ from calibre.utils.config import config_dir from calibre.utils.date import isoformat, now, parse_date from calibre.utils.localization import get_lang from calibre.utils.logging import Log -from calibre.utils.zipfile import ZipFile, safe_replace +from calibre.utils.zipfile import ZipFile from PIL import Image as PILImage @@ -1727,7 +1727,6 @@ class ITUNES(DriverBase): return thumb_data thumb_path = book_path.rpartition('.')[0] + '.jpg' - format = book_path.rpartition('.')[2].lower() if isosx: title = book.name() elif iswindows: diff --git a/src/calibre/ebooks/metadata/covers.py b/src/calibre/ebooks/metadata/covers.py new file mode 100644 index 0000000000..af213d1a6c --- /dev/null +++ b/src/calibre/ebooks/metadata/covers.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + + +from calibre.customize import Plugin + +class CoverDownload(Plugin): + + supported_platforms = ['windows', 'osx', 'linux'] + author = 'Kovid Goyal' + type = _('Cover download') diff --git a/src/calibre/web/feeds/templates.py b/src/calibre/web/feeds/templates.py index 4f26a35a02..1b2ba11e9c 100644 --- a/src/calibre/web/feeds/templates.py +++ b/src/calibre/web/feeds/templates.py @@ -8,7 +8,7 @@ import copy from lxml import html, etree from lxml.html.builder import HTML, HEAD, TITLE, STYLE, DIV, BODY, \ - STRONG, EM, BR, SPAN, A, HR, UL, LI, H2, H3, IMG, P as PT, \ + STRONG, BR, SPAN, A, HR, UL, LI, H2, H3, IMG, P as PT, \ TABLE, TD, TR from calibre import preferred_encoding, strftime, isbytestring