From cea5261e1207593889ef2be1165de11852b9b1bd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 22 Dec 2010 11:05:12 -0700 Subject: [PATCH] NRC EPUB version by veezh --- resources/recipes/nrc-nl-epub.recipe | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 resources/recipes/nrc-nl-epub.recipe diff --git a/resources/recipes/nrc-nl-epub.recipe b/resources/recipes/nrc-nl-epub.recipe new file mode 100644 index 0000000000..da9b9195ce --- /dev/null +++ b/resources/recipes/nrc-nl-epub.recipe @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#Based on Lars Jacob's Taz Digiabo recipe + +__license__ = 'GPL v3' +__copyright__ = '2010, veezh' + +''' +www.nrc.nl +''' +import os, urllib2, zipfile +import time +from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ptempfile import PersistentTemporaryFile + + +class NRCHandelsblad(BasicNewsRecipe): + + title = u'NRC Handelsblad' + description = u'De EPUB-versie van NRC' + language = 'nl' + lang = 'nl-NL' + + __author__ = 'veezh' + + conversion_options = { + 'no_default_epub_cover' : True + } + + def build_index(self): + today = time.strftime("%Y%m%d") + domain = "http://digitaleeditie.nrc.nl" + + url = domain + "/digitaleeditie/helekrant/epub/nrc_" + today + ".epub" +# print url + + try: + f = urllib2.urlopen(url) + except urllib2.HTTPError: + self.report_progress(0,_('Kan niet inloggen om editie te downloaden')) + raise ValueError('Krant van vandaag nog niet beschikbaar') + + tmp = PersistentTemporaryFile(suffix='.epub') + self.report_progress(0,_('downloading epub')) + tmp.write(f.read()) + tmp.close() + + zfile = zipfile.ZipFile(tmp.name, 'r') + self.report_progress(0,_('extracting epub')) + + zfile.extractall(self.output_dir) + + tmp.close() + index = os.path.join(self.output_dir, 'content.opf') + + self.report_progress(1,_('epub downloaded and extracted')) + + return index