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 10-09-2011, 12:36 PM   #1
davide125
Member
davide125 began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Mar 2011
Device: Amazon Kindle 3G
recipe for past Economist issues

Hi,

I've realized today that The Economist past issues can now be accessed even without a subscription. Here's a recipe to fetch an arbitrary old issue. It uses the subclassing trick from
https://www.mobileread.com/forums/sho...d.php?t=149319

Is there a way to override the publication date? It'd be nice to have it set to the issue date.

Code:
#!/usr/bin/env python

__license__   = 'GPL v3'
__copyright__ = '2011, Davide Cavalca <davide at cavalca dot name>'
'''
economist.com
'''

def LoadBuiltinRecipe(recipeName, moduleName):
    """ Load a built-in recipe into a python module
        recipeName is the filename of the recipe within builtin_recipes.zip
        moduleName is a unique name for the module
    """
    from zipfile import ZipFile

    with ZipFile(P('builtin_recipes.zip',allow_user_override=False)) as recipes:
        from imp import new_module
        import sys

        zf = recipes.open(recipeName)
        mod = new_module(moduleName)
        mod.__file__ = moduleName
        exec zf.read() in mod.__dict__
        sys.modules[moduleName] = mod
        cls = getattr(mod, moduleName)

        return cls

class EconomistPast(LoadBuiltinRecipe('economist.recipe', 'Economist')):
    needs_subscription = True

    description = ('Global news and current affairs from a European'
            ' perspective. Set the issue date (YYYY-MM-DD) as'
            ' username, the password field is ignored')
    __author__ = "Davide Cavalca"

    def parse_index(self):
        self.INDEX = "%s/%s" %(self.INDEX, self.username)
        return self.economist_parse_index()

    def get_cover_url(self):
        from datetime import date

        ymd = self.username.split('-')
        issue = date(int(ymd[0]), int(ymd[1]), int(ymd[2]))
        if issue >= date(2011,8,6):
          cover_url = "http://media.economist.com/sites/default/files/imagecache/print-cover-full/print-covers/%s_CNA400.jpg" %(''.join(ymd))
        elif issue >= date(2010,9,11):
          cover_url = "http://media.economist.com/sites/default/files/imagecache/print-cover-full/%s_CNA400.jpg" %(''.join(ymd))
        elif issue >= date(2002,10,12):
          cover_url = "http://media.economist.com/sites/default/files/imagecache/print-cover-full/%sissuecovEU400_0.jpg" %(''.join(ymd))
        else:
          cover_url = "http://media.economist.com/sites/default/files/imagecache/print-cover-full/%sissuecov.jpg" %(''.join(ymd))

        return cover_url
Davide
davide125 is offline   Reply With Quote
Old 10-09-2011, 06:20 PM   #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,194
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Set the timefmt to whatever you want.
kovidgoyal is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Downloading older Economist issues partymonkey Recipes 10 11-28-2011 10:09 AM
better cover for Economist recipe davide125 Recipes 5 11-12-2011 12:33 PM
Economist recipe jdomingos76 Recipes 1 03-08-2011 08:33 AM
Economist Free Recipe geneaber Calibre 10 12-31-2009 03:45 PM
Fetching Past NYTimes issues strico Calibre 0 09-29-2009 06:32 PM


All times are GMT -4. The time now is 07:33 AM.


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