02-26-2011, 09:42 AM | #1 |
Calibre Plugins Developer
Posts: 4,652
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Converting text for a datetime custom column
I'm working on one last (cough) addition to the Goodreads sync plugin before I release it, and that is adding the ability to create an action which sets a datetime custom column using either a value from the Goodreads API xml or the current timestamp. So for instance someone who wants a custom column in Calibre representing the date they last read the book could get that value populated by syncing from their Goodreads shelf.
The bit I would appreciate help with is the datetime parsing, and getting a value in the right format to pass to db.set_custom(). Goodreads will supply values in their xml API that look like this: Code:
<date_added>Mon Feb 21 03:48:31 -0800 2011</date_added> <date_updated>Mon Feb 21 03:48:31 -0800 2011</date_updated> <started_at/> <read_at/> 1. What I need to do to convert a variable holding one of those text dates into a value I could pass to db.set_custom()? 2. What I should pass to use a current timestamp? 3. If I were to call db.get_custom() to compare values before deciding to update, what tricks if any I may need to check for equality? Many thanks |
02-26-2011, 10:00 AM | #2 | ||
Grand Sorcerer
Posts: 11,787
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
Code:
from calibre.utils.date import parse_date, now dt1 = parse_date("Mon Feb 21 03:48:31 -0800 2011") print dt1 dt2 = now() print dt2 print 'dt1 == dt1', dt1 == dt1 print 'dt1 == dt2', dt1 == dt2 print 'dt1 < dt2', dt1 < dt2 print 'dt1 > dt2', dt1 > dt2 print 'dt2 == dt2', dt2 == dt2 Code:
C:\CBH_Data\calibre_development>calibre-debug -e foo2.py 2011-02-21 11:48:31+00:00 2011-02-26 14:57:48.988000+00:00 dt1 == dt1 True dt1 == dt2 False dt1 < dt2 True dt1 > dt2 False dt2 == dt2 True C:\CBH_Data\calibre_development> |
||
Advert | |
|
02-26-2011, 10:47 AM | #3 | |
Calibre Plugins Developer
Posts: 4,652
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Yeah I know, hopeless aren't I? I also put in an autocompletion line edit for if the user sets up actions for a Tags column. So much for all those "lies" I have been telling to all the people PM'ing me for releases in saying the version I gave them would be the last...
Quote:
All working now. Must be time to release it... |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need help with this custom Column. | Rie142 | Library Management | 2 | 02-20-2011 09:51 AM |
Custom text column with no HTML | mfaine | Calibre | 2 | 01-07-2011 01:12 PM |
Custom column read ? | pchrist7 | Calibre | 2 | 10-04-2010 02:52 AM |
custom column i need a little help | shinken | Calibre | 3 | 09-15-2010 03:41 AM |
custom column not searchable | SkyDream | Calibre | 5 | 07-26-2010 05:38 AM |