Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 02-26-2011, 09:42 AM   #1
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,601
Karma: 2092290
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/>
Could anyone (and yeah it's probably you chaley as Mr Custom Column ) please tell me:
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
kiwidude is offline   Reply With Quote
Old 02-26-2011, 10:00 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,703
Karma: 6658935
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
I'm working on one last (cough) addition to the Goodreads sync plugin before I release it

Quote:
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/>
Could anyone (and yeah it's probably you chaley as Mr Custom Column ) please tell me:
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?
I think the following sample answers all three questions.
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
Output is:
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>
chaley is offline   Reply With Quote
Advert
Old 02-26-2011, 10:47 AM   #3
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,601
Karma: 2092290
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Quote:
Originally Posted by chaley View Post
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:
I think the following sample answers all three questions.
Perfect. Didn't realise it would be quite that simple, thought I had a world of pain of date conversions, time zones and formats ahead. I like your answer

All working now. Must be time to release it...
kiwidude is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 11:02 AM.


MobileRead.com is a privately owned, operated and funded community.