Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Hack Para Catalogar Libros

import sys
import time
import gdata.books.service
import json

def get_book_info(isbn):
    print "Looking for ISBN:", isbn
    google_books = gdata.books.service.BookService()
    result = google_books.search('ISBN %s '%isbn)
    data = [x.to_dict() for x in result.entry]
    if not data:
        print "No results"
        return
    title = data[0]['title']
    with open(title+'.json','w') as f:
        f.write(json.dumps(data))
    print "Guardada info de '%s' en '%s.json'" %(isbn, title)

if __name__ == "__main__":
    while True:
        isbn = sys.stdin.readline().strip()
        if isbn:
            get_book_info(isbn)
        time.sleep(1)

¿Qué ha­ce? Lee nú­me­ros IS­BN y guar­da la da­ta del li­bro en "tí­tu­lo­.­j­so­n" pa­ra que des­pués lo pro­ce­ses y for­ma­tees.

Si que­rés edi­tar esa in­fo, po­dés usar un edi­tor de tex­to, o usar jso­nwi­dget y un po­co de as­tu­cia así:

python -c 'import jsonwidget; jsonwidget.run_editor("abook.json", schemafile="gbooks.schema")'

En ese co­man­do abook.­j­son es un ar­chi­vo ge­ne­ra­do por el script an­te­rio­r, y gbooks.­che­ma es es­te ar­chi­vo.

Ah, y si tus li­bros tie­nen có­di­gos de ba­rra...

zbarcam --raw | python bookdata.py

Le mos­trás los li­bros a la com­pu y ella ha­ce el res­to :-)

PD: es­ta­ría bue­ní­si­mo que al­guien hi­cie­ra una app de ca­tá­lo­go de li­bros con es­tas co­sas ;-)

Pablo Valentini / 2012-07-13 18:01:

Tenés un pequeño error en la línea 17.

Saludos.

Roberto Alsina / 2012-07-13 18:08:

Gracias, arreglado!

Walter Alini / 2012-07-13 23:26:

Tenés un pequeño error en "gbooks.chema"

Giacomo Lacava / 2012-07-14 15:38:

It's 2012, dude :) there are so many online options without having to hack your own... LibraryThing, Goodreads, Anobii, etc etc.

The real problem is reading all those ISBN. I wish there was an iPhone app that just reads a barcode and adds it to a list, which you can then export, so that you can do mass-scanning in a few minutes. Probably there is one out there I don't know about.

Roberto Alsina / 2012-07-14 15:49:

If you just want to read the ISBNs, then zbarcam and a webcam is enough, or zbar for android (no idea about iPhone).

I use goodreads a lot, actually. The goal here is to give you your data, in your device, for you. Relying exclusively on online services from which there is no easy exit strategy is not something I like a lot.

Giacomo Lacava / 2012-07-14 22:01:

http://www.goodreads.com/re... on the right has a link to export in csv format. Just sayin'.

Roberto Alsina / 2012-07-14 22:08:

Ever tried reading that CSV file? I did :-) LibreOffice, at least, fails miserably.

In any case, if you want to load your books into goodreads, use this script and then import them. Noone is stopping you :-)


Contents © 2000-2023 Roberto Alsina