05-25-2010, 01:19 AM | #1981 |
Junior Member
Posts: 4
Karma: 10
Join Date: May 2010
Device: none
|
Thanks for your input and insights, dwanthny and Starson17.
So far, I have not been able to make either to work. Spent the evening googling Python, and not really grasping it yet. One thing I tried, was " insert(url[:40] + 'v-print/' + url[40:]) ", to break the url at the 40th character, insert the "v-print", and then continue (since the date is always the same number of characters, using 2 digits for even a single digit month or day), but I don't have the form or syntax right yet. I also tried looking for a newspaper from the same publisher (McClatchy) in the included recipes, hoping that their web templates might be the same. So far, haven't found anything. |
05-25-2010, 01:22 AM | #1982 | |
Junior Member
Posts: 4
Karma: 10
Join Date: May 2010
Device: Nook
|
Hi,
Is there anyway to customize the filename using the recipe? Currently a news file will be named something like "Newsweek_2010-5-24.epub" I would like it to read "Newsweek.epub". This way when calibre moves over files to my nook it should just overwrite the old effectively deleting obsolete news. Thanks Quote:
Last edited by mik991; 05-25-2010 at 11:57 AM. |
|
Advert | |
|
05-25-2010, 07:50 AM | #1983 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
|
|
05-25-2010, 12:13 PM | #1984 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
I am not a Python expert, so I'm not the one to ask. I've never tried to use wildcards outside of the regular expression context. All I can say is that I've seen the insert-something-into-url problem solved several times in recipes, and it's always been just a split-at-slash and reassemble or a regex solution.
|
05-25-2010, 12:19 PM | #1985 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
wildcards do not work, you have to use a regular expression or the fnmatch module if you want to use wildcards.
|
Advert | |
|
05-25-2010, 12:26 PM | #1986 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Second, I don't think you can insert into a string in Python - instead, you create a new string. You might try this: Code:
url2 = url[:40] + 'v-print/' + url[40:] return url2 |
|
05-25-2010, 12:31 PM | #1987 |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
When first trying to understand regular expressions, I asked a friend for help. IIRC, his answer was something like .. "If you have a problem that needs to be solved with a regular expression ... now you have two problems."
|
05-25-2010, 02:28 PM | #1988 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
But I must say that having learning regular expressions has boosted my productivity by an order of magnitude.
|
05-25-2010, 05:24 PM | #1989 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I have been a user of regular expressions since my early ed/ex/vi days in the early '70s. I can't imagine working on text without them. I remember 'grokking' (shows my age) that a regexp is just a description/template/pattern, and the lights turned on.
If you enjoy constructing regexps, play a bit with (f)lex, a program that generates lexical analyzers that can read files with known structure and split them into usable 'words' (technically, tokens). I am often surprised by how many problems are amenable to solution by a combination of lexical processing and subsequent parsing. Yes, I know I am weird. Can't help it, and really don't want to change. |
05-25-2010, 08:12 PM | #1990 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yeah calibre uses pyparsing to build the parser that tokenizes the search strings. While I haven't used lex/yacc at all, I do enjoying working with pyparsing.
http://onlamp.com/pub/a/python/2006/...pyparsing.html |
05-25-2010, 08:13 PM | #1991 |
Junior Member
Posts: 4
Karma: 10
Join Date: May 2010
Device: none
|
Thanks for everyone's help!! Especially the link to recipe guide, that I did not find by Googling.
Here's what I came up with, a little tweaking of Starson17's original suggestion Code:
def print_version(self, url): segments = url.split('/') print_url = 'http://' + segments[2] + '/' + segments[3] + '/' + segments[4] + '/' + segments[5] + '/' \ + 'v-print/' + segments[6] + '/' + segments[7] return print_url This is really exciting! And now I need to spend some time learning about Python, is there a "Python for Dummies"? Thanks again!!! |
05-26-2010, 10:53 PM | #1993 |
Enthusiast
Posts: 49
Karma: 10
Join Date: Aug 2009
Device: none
|
REQUEST FOR RECIPE
I WOULD LIKE TO REQUEST A RECIPE FOR
http://knowledge.wharton.upenn.edu/india/rss/ AND http://knowledge.wharton.upenn.edu/rss/ |
05-27-2010, 05:26 PM | #1994 |
Connoisseur
Posts: 54
Karma: 1140
Join Date: Apr 2010
Device: Kindle / Palm Pre / iPhone
|
Hoping someone can help me with the Wired Magazine recipe, which the latest June 2010 issue seems to have broken.
Calibre is giving me the dreaded "AttributeError: 'NoneType' object has no attribute 'a'" error: It's happening here: File "c:\docume~1\darryl~1\locals~1\temp\calibre_0.6.54 _jujqqs_recipes\recipe0.py", line 79, in parse_index url = 'http://www.wired.com' + divurl.a['href'] Looking at the source at http://www.wired.com/magazine I think the problem may be that Wired has added a new "Bonus Video" section which does not have a feature-header div, and so the URL cannot be parsed from there. Is there anyways to have Calibre skip feature sections that don't have headers? Thanks! |
05-27-2010, 08:59 PM | #1995 |
Guru
Posts: 800
Karma: 194644
Join Date: Dec 2007
Location: Argentina
Device: Kindle Voyage
|
I'll look into that this weekend if time permits
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom column read ? | pchrist7 | Calibre | 2 | 10-04-2010 02:52 AM |
Archive for custom screensavers | sleeplessdave | Amazon Kindle | 1 | 07-07-2010 12:33 PM |
How to back up preferences and custom recipes? | greenapple | Calibre | 3 | 03-29-2010 05:08 AM |
Donations for Custom Recipes | ddavtian | Calibre | 5 | 01-23-2010 04:54 PM |
Help understanding custom recipes | andersent | Calibre | 0 | 12-17-2009 02:37 PM |