Search code examples
pythonweb2pyisbn

Using isbntools with web2py


I'm using web2py to create a page where I search for books based on title/author/keyword/etc. and ISBN, and I can't seem to figure out how to use isbntools in the webapp. I'm sure it's something basic that I'm missing out on, but this is the first webapp that I've ever created, and it's for a class project. This is the related portion of my controller:

from isbntools import *

def index():
    form=SQLFORM.factory(
     Field('title',label='Try entering a title:'),
     Field('author',label='Or an author:'),
     Field('ISBN',label='Even better if you have the ISBN'),
     Field('fromDate',label='When is the earliest the book might have come out?'),
     Field('toDate',label='...and the latest?'))
    if form.process().accepted:
        titledata = isbn_goom form.vars.title bibtex
        authordata = isbn_goom form.vars.author bibtex
        isbndata = isbn_meta merge form.vars.ISBN bibtex
        print(titledata)
        print(authordata)
        print(isbndata)
    return dict(form=form)

This is a portion of the ticket information I'm getting back:

Error ticket for "Bibbly" Ticket ID

96.255.27.81.2014-05-01.21-50-27.f66e0b53-b5bd-4621-8dbd-b6f30e8a6af1 invalid syntax (default.py, line 21) Version web2py™ Version 2.8.2-stable+timestamp.2013.11.28.13.54.07 Python Python 2.7.5+: /usr/local/bin/uwsgi (prefix: /usr) Traceback

line 21 titledata = isbn_goom "form.vars.title" bibtex ^ SyntaxError: invalid syntax


Solution

  • isbm_goom is a command line script. Is that what you want?! (you cannot use it in your code like that!)

    I suggests you use the most recent version of isbntools and adapt this snipet

    from isbntools.contrib.modules.goom import goom
    from isbntools.dev.fmt import fmtbib
    

    ...

    titledata = goom.query(form.vars.title)
    for r in titledata:
        print((fmtbib('bibtex', r)))