View Single Post
Old 03-21-2013, 07:45 PM   #1
realbase
Junior Member
realbase began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2013
Device: Kobo Glo
Dutch Weekly Newspaper "De Groene Amsterdammer" Recipe

This is the Recipe I'd built for "De Groene Amsterdammer" (for readers with a subscription only). They publish their new edition each wednesday-evening. I set mine to thursday-morning. Have fun with it!

Code:
#!/usr/bin/env  python2
# -*- coding: utf-8 -*-
#Based on veezh's original recipe and Kovid Goyal's New York Times recipe and Snaab's NRC-epub recipe

__license__   = 'GPL v3'
__copyright__ = '2013, RealBase'

'''
www.groene.nl
'''
import os, zipfile
import time
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ptempfile import PersistentTemporaryFile
from calibre.ebooks.conversion.cli import main

class GroeneAmsterdammer(BasicNewsRecipe):

    title = u'De Groene Amsterdammer'
    description = u'De ePub-versie van de Groene Amsterdammer'
    language = 'nl'
    lang = 'nl-NL'
    needs_subscription = True

    __author__ = 'Realbase'

    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('https://www.groene.nl/sessie/new')
            print [form for form in br.forms()][1]          
            br.select_form(nr=1)
            br['user_session[login]']   = self.username
            br['user_session[password]'] = self.password
            br.submit()
        return br

    def build_index(self):

        domain = "http://www.groene.nl"

        url = domain + "/deze-week.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('Groene van deze week nog niet beschikbaar')

        tmp = PersistentTemporaryFile(suffix='.epub')
        self.report_progress(0,_('downloading epub'))
        tmp.write(f.read())
        f.close()
        br.close()
        tmp.close()

        # convert
        self.report_progress(0.2,_('Converting to OEB'))
        oebdir = self.output_dir + '/INPUT/'
        main(['ebook-convert', tmp.name, oebdir])
        index = os.path.join(oebdir, 'content.opf')
        self.report_progress(1,_('epub downloaded and extracted'))


        return index
Please leave a comment if you use it!
realbase is offline   Reply With Quote