01-23-2011, 09:42 AM | #1 |
Groupie
Posts: 155
Karma: 106422
Join Date: Nov 2010
Device: none
|
Problem with Article Date in parse_index
I'm having an issue trying to override the default date/time that gets put in the article. The strange thing is that it seems to work fine in one of my recipes but can't get it to "take" in the other recipe.
When I do a self.log on the result of my regular expression, everything looks fine. But when the EPUB file gets created, it defaults to the date that would get generated if I had passed in a blank string to the article dictionary: [Sun, 23 Jan 08:36] I should be able to use any string that I want for the date, correct? Or is there something in the EPUB generation that tries to detect a valid date or something? Any help appreciated... Here is my code: Code:
pattern2 = r'AID=\/(.*?)\/' reg2 = re.compile(pattern2, re.IGNORECASE|re.DOTALL) match2 = reg2.search(thisurl) if match2: c = time.strptime(match2.group(1),"%Y%m%d") mydate=time.strftime("%a, %b %d, %Y", c) else: mydate = time.strftime("%a, %b %d, %Y") self.log(mydate) articles.append({ 'title' :thistitle ,'date' :' {' + mydate + '}' ,'url' :thisurl ,'description':description }) |
01-23-2011, 12:05 PM | #2 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
That date is used only in the section index of links pointing to articles, not in the article itself.
|
Advert | |
|
01-23-2011, 08:17 PM | #3 |
Groupie
Posts: 155
Karma: 106422
Join Date: Nov 2010
Device: none
|
Thanks for the quick response (as always, of course).
I should have been more clear in my question - it is the TOC that I'm talking about where the date doesn't seem to be working. No matter what I end up passing in, all the links in the TOC have the current datetime instead of what I send in. I'll keep playing around with it - it's not a big deal... the rest of the recipe seems to be working fine. |
02-19-2011, 07:01 PM | #4 |
Groupie
Posts: 155
Karma: 106422
Join Date: Nov 2010
Device: none
|
Yay! I finally found what was going on here.
After getting the string formatted just like I wanted: mydate=time.strftime("%a, %b %d, %Y", c) I had to somehow convert it to a unicode string before adding it as an article. So instead of this: 'date' :' {' + mydate + '}' I needed this: 'date' :u' {' + mydate + '}' All good now... |
02-19-2011, 07:09 PM | #5 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Rather than using time.strftime, instead use
from calibre import strftime strftime(...) this will always return unicode strings. |
Advert | |
|
02-19-2011, 07:12 PM | #6 |
Groupie
Posts: 155
Karma: 106422
Join Date: Nov 2010
Device: none
|
Awesome - thanks for the heads-up on that. That'll help keep it clean...
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Date Problem | deppeler | Calibre | 3 | 01-11-2011 11:44 PM |
Bulk Changing Published Date To Date | hmf | Calibre | 4 | 10-19-2010 10:19 PM |
Article Dates with parse_index | EnergyLens | Calibre | 6 | 04-21-2010 10:13 PM |
Omitting description an author in parse_index | nickredding | Calibre | 0 | 12-31-2009 04:19 PM |
Problem with date resetting | nathantw | Sony Reader | 5 | 02-01-2008 02:57 PM |