From c06c4522fd5bae233774174095ef098597553910 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 10 May 2013 20:44:54 +0530 Subject: [PATCH] nrc-next by Niels Giesen --- recipes/nrc_next.recipe | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 recipes/nrc_next.recipe diff --git a/recipes/nrc_next.recipe b/recipes/nrc_next.recipe new file mode 100644 index 0000000000..bd23a37c65 --- /dev/null +++ b/recipes/nrc_next.recipe @@ -0,0 +1,75 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# Based on veezh's original recipe, Kovid Goyal's New York Times recipe and Snaabs nrc Handelsblad recipe + +__license__ = 'GPL v3' +__copyright__ = '2013, Niels Giesen' + +''' +www.nrc.nl +''' +import os, zipfile +import time +from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ptempfile import PersistentTemporaryFile + + +class NRCNext(BasicNewsRecipe): + + title = u'nrc•next' + description = u'De ePaper-versie van nrc•next' + language = 'nl' + lang = 'nl-NL' + needs_subscription = True + + __author__ = 'Niels Giesen' + + conversion_options = { + 'no_default_epub_cover' : True + } + + def get_browser(self): + br = BasicNewsRecipe.get_browser(self) + if self.username is not None and self.password is not None: + br.open('http://login.nrc.nl/login') + br.select_form(nr=0) + br['username'] = self.username + br['password'] = self.password + br.submit() + return br + + def build_index(self): + + today = time.strftime("%Y%m%d") + + domain = "http://digitaleeditie.nrc.nl" + + url = domain + "/digitaleeditie/helekrant/epub/nn_" + today + ".epub" + #print url + + try: + br = self.get_browser() + f = br.open(url) + except: + 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()) + f.close() + br.close() + if zipfile.is_zipfile(tmp): + try: + zfile = zipfile.ZipFile(tmp.name, 'r') + zfile.extractall(self.output_dir) + self.report_progress(0,_('extracting epub')) + except zipfile.BadZipfile: + self.report_progress(0,_('BadZip error, continuing')) + + tmp.close() + index = os.path.join(self.output_dir, 'metadata.opf') + + self.report_progress(1,_('epub downloaded and extracted')) + + return index