Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 05-10-2013, 06:35 AM   #1
vdHummes
Junior Member
vdHummes began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2009
Device: Android
New recipe for nrc•next (subscription version)

Here is a recipe for the dutch weekday morning newspaper nrc•next.

You need a subscription to use it. It is based on the recipe for NRCHandelsblad.

Code:
#!/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
vdHummes is offline   Reply With Quote
Old 05-10-2013, 06:57 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,351
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Is there some difference to the existing builtin nrc handelsblad recipe?
kovidgoyal is online now   Reply With Quote
Advert
Old 05-10-2013, 07:37 AM   #3
vdHummes
Junior Member
vdHummes began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2009
Device: Android
Yes, it is a different newspaper, though by the same publisher (NRC Handelsblad is lengthier and an afternoon paper).

Besides some different names, to differentiate nrc next from NRC Handelsblad, the code functionally differs only marginally: in the URL where the epub file is to be fetched:

Code:
*** 44,50 ****
  
          domain = "http://digitaleeditie.nrc.nl"
  
!         url = domain + "/digitaleeditie/helekrant/epub/nrc_" + today + ".epub"
          #print url
  
          try:
--- 44,50 ----
  
          domain = "http://digitaleeditie.nrc.nl"
  
!         url = domain + "/digitaleeditie/helekrant/epub/nn_" + today + ".epub"
          #print url
  
          try:
vdHummes is offline   Reply With Quote
Old 05-10-2013, 11:14 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,351
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Ah, ok, thanks.
kovidgoyal is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New NRC Handelsblad recipe with all formats downloaded in single calibredb entry smmadge Recipes 0 10-17-2012 03:26 AM
Recipe for NRC Handelsblad (RSS feeds) veezh Recipes 5 03-29-2012 04:39 AM
recipe for newspaper subscription www.nd.nl NicoDeMus! Recipes 0 11-24-2011 05:02 PM
How to use recipe with subscription from command line miwie Calibre 3 11-23-2010 04:10 AM
NRC (Dutch newspaper) offering ePub version Nvidiot News 5 10-27-2009 06:18 AM


All times are GMT -4. The time now is 05:39 AM.


MobileRead.com is a privately owned, operated and funded community.