diff --git a/python/worblehat.py b/python/worblehat.py index e56800e..d829a95 100755 --- a/python/worblehat.py +++ b/python/worblehat.py @@ -4,20 +4,34 @@ import os os.environ['DJANGO_SETTINGS_MODULE']='web.settings' from web.library.models import * +from web.library.fileformat import read_actionlist, write_actionlist from django.db.models import Q from util import * import getopt import sys +import types import search import placement def show_book_or_person(ids, commit_format=False, tmp_file=False): - for id in ids: - object = get_book_or_person(id) - if object: - print object.to_string() + objects = map(get_book_or_person, ids) + for i in range(len(ids)): + if not objects[i]: + objects[i] = 'No book or person with id %s.' % id + elif commit_format: + objects[i] = objects[i].to_dict() else: - print 'No book or person with id %s.' % id + objects[i] = objects[i].to_string() + if commit_format: + output = write_actionlist(objects) + else: + output = '\n'.join(objects) + if tmp_file: + # TODO + #return write_tmpfile('-'.join(ids), output) + pass + else: + print output def get_book_or_person(id): books = Book.objects.filter(Q(isbn=id)|Q(id__id=id)).all()