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