View Single Post
Old 07-23-2014, 03:35 AM   #13
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: 45,440
Karma: 27757438
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Since I was here in any case, I decided to add a --for-machine option to calibredb list that makes it easier to parse the output.

And here's a one liner (in python because I hate sh) that demonstrates how to get a list of all ids and formats for ever id in the library

Code:
calibredb list --for-machine -f formats | python2 -c "import sys; print '\n\n'.join('id:%s formats:%r' % (r.partition(chr(29))[0], r.partition(chr(29))[-1].split(chr(28))) for r in sys.stdin.read().split(chr(30)) if r.strip())"
And the help of --for-machine

Code:
  --for-machine         Generate output that is more suitable for machine
                        parsing. Book entries are separates using the ASCII
                        Record Separator character (30), individual fields in
                        an entry using the Group Separator (29) and individual
                        filenames using the File Separator (28)
kovidgoyal is offline   Reply With Quote