|
|
#1 |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Oct 2011
Device: Kindle 4
|
The Economist - past issues
I am trying to modify the current recipe for The Economist so that I can download past issues of the magazine.
This code works perfectly well, but requires the user to modify the recipe each time one wants a different issue: Spoiler:
Now I would like to use the input from the username field to modify INDEX. Something like: Code:
issue = self.username INDEX = 'http://www.economist.com/printedition/%s' % (issue.translate(None,'-')) Any hint on how I can modify INDEX with data from self.username? Would that mean modifying __init__ files? |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,617
Karma: 28549044
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
In python self refers to an object instantiated from a class, you cannot use it in class level variables. Instead of using it with INDEX, you should replace the use of INDEX in the rest of the recipe.
|
|
|
|
| Advert | |
|
|
|
|
#3 | |
|
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Oct 2011
Device: Kindle 4
|
I have tried and it doesn't work. The variable that is called has to be defined in the class Economist. I can't define it later, or else I get an error
Quote:
Global vars don't work either. The "username" variable used in self.username is not available unless inside functions... So I can't use the user input while defining class variables... |
|
|
|
|
|
|
#4 |
|
Reader
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 520
Karma: 24612
Join Date: Aug 2009
Location: Utrecht, NL
Device: Kobo Aura 2, iPhone, iPad
|
You can get rid of the class variable INDEX and just use an instance variable. Like this:
Code:
def get_browser(self):
self.INDEX = 'http://www.economist.com/printedition/'+self.username
return BasicNewsRecipe.get_browser()
def get_cover_url(self):
br = self.browser
br.open(self.INDEX)
self.log('Fetching cover for issue: ')
date = self.username.replace('-', '')
cover_url = "http://media.economist.com/sites/default/files/imagecache/print-cover-full/%s_CNA400.jpg" % date
return cover_url
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Downloading older Economist issues | partymonkey | Recipes | 10 | 11-28-2011 11:09 AM |
| recipe for past Economist issues | davide125 | Recipes | 1 | 10-09-2011 07:20 PM |
| Portrait of the Past | khalleron | Self-Promotions by Authors and Publishers | 15 | 12-08-2010 11:41 AM |
| Fetching Past NYTimes issues | strico | Calibre | 0 | 09-29-2009 07:32 PM |
| A blast from the past | cbarnett | Introduce Yourself | 7 | 08-29-2007 12:11 PM |