View Single Post
Old 02-26-2011, 10:00 AM   #2
chaley
"chaley", not "charley"
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: 5,441
Karma: 831552
Join Date: Jan 2010
Location: France
Device: Many android devices
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