Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 10-14-2012, 01:29 PM   #1
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,111
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
CLI: calibredb add_custom_column

Tried looking through the manual and searching the forums but wasn't able to find the info I needed.

1. Is it possible to use calibredb add_custom_column command line for creating composite columns with the template already populated? So far, I've only been able to use it for creating composite columns with an empty template.

2. How do I use the --display option for formatting dates? (e.g. MM/dd/yy: 12/31/12)

Thank you very much in advance!
ilovejedd is offline   Reply With Quote
Old 10-17-2012, 09:32 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
IIRC it isn't possible, but chaley is the one who can give you a definitive answer.
kovidgoyal is offline   Reply With Quote
Old 10-17-2012, 01:49 PM   #3
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,740
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The template goes into the display variable, which is JSON encoded. You can see what it should be by looking at the OPF for a book in your library. One example is
Code:
{"composite_template": "{:'approximate_formats()'}", 
"contains_html": false, 
"make_category": true, 
"composite_sort": "text"
}
I strongly recommend that you look at the OPF because there are several fields that can play a role.

Regarding date formatting, this is also a JSON-encoded string. One example is
Code:
{ "date_format": "yyyy/MM/dd" }
chaley is offline   Reply With Quote
Old 10-17-2012, 11:02 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@chaley: Maybe we should add some examples to the documentation of that command, or at least a line telling the user to look at OPF files.
kovidgoyal is offline   Reply With Quote
Old 10-18-2012, 02:28 PM   #5
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,111
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Quote:
Originally Posted by chaley View Post
The template goes into the display variable, which is JSON encoded. You can see what it should be by looking at the OPF for a book in your library. One example is
Code:
{"composite_template": "{:'approximate_formats()'}", 
"contains_html": false, 
"make_category": true, 
"composite_sort": "text"
}
I strongly recommend that you look at the OPF because there are several fields that can play a role.
Yeah, I've actually looked through the OPFs and created copies of custom columns reformatted to be human legible (" to " then prettied up the resulting JSON with Notepad++). Still trying to get the date format right before I try anything more complex.

Quote:
Originally Posted by chaley View Post
Regarding date formatting, this is also a JSON-encoded string. One example is
Code:
{ "date_format": "yyyy/MM/dd" }
This, I've actually kinda tried (on Windows XP CLI). I believe I used the following:
Code:
--display='{"date_format":"MM/dd/yy"}'
Will have to double-check the actual batch file I used when I get home but I remember getting a message saying "No JSON object found" or something. For some reason, the batch file automatically terminates in XP (even though I explicitly added pause) so it's difficult to get the complete error message.

Edit:
I believe calibredb custom_columns -d would also show the basic JSON structure. Shows everything in single-quotes, though, but easy enough to figure out which needs to be converted to double-quotes.

Last edited by ilovejedd; 10-18-2012 at 02:40 PM.
ilovejedd is offline   Reply With Quote
Old 10-18-2012, 02:54 PM   #6
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,111
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Since I'm working on Windows 7 right now, tried to see if I can get the full error message.

CLI:
Code:
calibredb add_custom_column --display '{"date_format":"MM/dd/yy"}' updated Updated datetime --with-library="Z:\library\fanfic"
Error Message:
Code:
Python function terminated unexpectedly
  No JSON object could be decoded (Error Code: 1)
Traceback (most recent call last):
  File "site.py", line 132, in main
  File "site.py", line 109, in run_entry_point
  File "site-packages\calibre\library\cli.py", line 1363, in main
  File "site-packages\calibre\library\cli.py", line 709, in command_add_custom_column
  File "json\__init__.py", line 326, in loads
  File "json\decoder.py", line 366, in decode
  File "json\decoder.py", line 384, in raw_decode
ValueError: No JSON object could be decoded
ilovejedd is offline   Reply With Quote
Old 10-19-2012, 01:51 AM   #7
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,740
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Apparently the Win7 CLI does not strip single quotes from arguments, making the JSON string invalid. The following works.
Code:
--display="{\"date_format\":\"MM/dd/yy\"}"
while this doesn't:
Code:
--display='{\"date_format\":\"MM/dd/yy\"}'
Putting print statements in the code, we see that the first arrives in calibre as
Code:
{"date_format":"MM/dd/yy"}
while the second second arrives as
Code:
'{"date_format":"MM/dd/yy"}'
(note the single quotes).

So, the solution for Win7 is to use double quotes and escape all internal quotes.
chaley is offline   Reply With Quote
Old 10-19-2012, 02:12 AM   #8
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,740
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kovidgoyal View Post
@chaley: Maybe we should add some examples to the documentation of that command, or at least a line telling the user to look at OPF files.
Pushed changes:
- list the valid display dict keys by datatype
- point toward the OPF to get examples
chaley is offline   Reply With Quote
Old 10-19-2012, 02:35 AM   #9
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,111
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Quote:
Originally Posted by chaley View Post
Apparently the Win7 CLI does not strip single quotes from arguments, making the JSON string invalid. The following works.
Code:
--display="{\"date_format\":\"MM/dd/yy\"}"
while this doesn't:
Code:
--display='{\"date_format\":\"MM/dd/yy\"}'
So, the solution for Win7 is to use double quotes and escape all internal quotes.
Cool, that works great. Thanks! Might want to add this bit of info to the documentation. By the way, same issue exists and solution works with Windows XP. Alas, I've just never been able to capture the whole error message in XP as the batch file terminates directly after the first calibredb run (known issue, problem with Windows XP so can't fix so I just use the start workaround).

Funnily enough, I tried:
Code:
--display="{'date_format':'MM/dd/yy'}"
and:
Code:
--display='{\"date_format\":\"MM/dd/yy\"}'
I thought I had also tried:
Code:
--display="{\"date_format\":\"MM/dd/yy\"}"
but apparently not.
ilovejedd is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
calibredb catalog CLI error ilovejedd Library Management 4 02-06-2012 10:26 AM
Cli-usage in plugins drMerry Development 8 09-24-2011 03:58 PM
Struggling with CLI Paulinafrica Calibre 4 01-08-2011 02:04 PM
prs505 cli ees Calibre 3 01-10-2009 03:27 AM


All times are GMT -4. The time now is 01:01 PM.


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