From 23dd44edc2dbc9e7fc0ad86bf84ebe937b0614db Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 29 May 2009 09:00:31 -0700 Subject: [PATCH] Fix #2515 (eBook Viewer cannot open TAZ epub file) --- src/calibre/ebooks/epub/iterator.py | 2 +- src/calibre/web/feeds/recipes/__init__.py | 1 + .../feeds/recipes/recipe_climate_progress.py | 47 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/calibre/web/feeds/recipes/recipe_climate_progress.py diff --git a/src/calibre/ebooks/epub/iterator.py b/src/calibre/ebooks/epub/iterator.py index a51a67b3a1..fa2e120e3f 100644 --- a/src/calibre/ebooks/epub/iterator.py +++ b/src/calibre/ebooks/epub/iterator.py @@ -94,7 +94,7 @@ class EbookIterator(object): ''' for item in self.opf.manifest: if item.mime_type and 'css' in item.mime_type.lower(): - css = open(item.path, 'rb').read().decode('utf-8') + css = open(item.path, 'rb').read().decode('utf-8', 'replace') for match in re.compile(r'@font-face\s*{([^}]+)}').finditer(css): block = match.group(1) family = re.compile(r'font-family\s*:\s*([^;]+)').search(block) diff --git a/src/calibre/web/feeds/recipes/__init__.py b/src/calibre/web/feeds/recipes/__init__.py index 6793c2864d..e522db86eb 100644 --- a/src/calibre/web/feeds/recipes/__init__.py +++ b/src/calibre/web/feeds/recipes/__init__.py @@ -44,6 +44,7 @@ recipe_modules = ['recipe_' + r for r in ( 'stackoverflow', 'telepolis_artikel', 'zaobao', 'usnews', 'straitstimes', 'index_hu', 'pcworld_hu', 'hrt', 'rts', 'h1', 'h2', 'h3', 'phd_comics', 'woz_die', 'elektrolese', + 'climate_progress', )] import re, imp, inspect, time, os diff --git a/src/calibre/web/feeds/recipes/recipe_climate_progress.py b/src/calibre/web/feeds/recipes/recipe_climate_progress.py new file mode 100644 index 0000000000..081997f7fe --- /dev/null +++ b/src/calibre/web/feeds/recipes/recipe_climate_progress.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +__license__ = 'GPL v3' +__copyright__ = '2009, Darko Miletic ' +''' +climateprogress.org +''' + +from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag + +class ClimateProgress(BasicNewsRecipe): + title = 'Climate Progress' + __author__ = 'Darko Miletic' + description = "An insider's view of climate science, politics and solutions" + publisher = 'Climate Progress' + category = 'news, ecology, climate, blog' + oldest_article = 7 + max_articles_per_feed = 100 + no_stylesheets = True + use_embedded_content = True + encoding = 'utf-8' + language = _("English") + lang = 'en-US' + direction = 'ltr' + + html2lrf_options = [ + '--comment', description + , '--category', category + , '--publisher', publisher + ] + + html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"' + + remove_tags = [dict(name='a', attrs={'rel':'bookmark'})] + + feeds = [(u'Posts', u'http://feeds.feedburner.com/climateprogress/lCrX')] + + def preprocess_html(self, soup): + soup.html['lang'] = self.lang + soup.html['dir' ] = self.direction + mlang = Tag(soup,'meta',[("http-equiv","Content-Language"),("content",self.lang)]) + mcharset = Tag(soup,'meta',[("http-equiv","Content-Type"),("content","text/html; charset=utf-8")]) + soup.head.insert(0,mlang) + soup.head.insert(1,mcharset) + return self.adeify_images(soup) +