From 4449493bbd760af8c263435b5acac8bc15a83bd2 Mon Sep 17 00:00:00 2001 From: gombos Date: Sat, 8 Oct 2011 19:53:24 +0000 Subject: [PATCH] implemented search-person --- cli/worblehat.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/worblehat.py b/cli/worblehat.py index 55e6c48..5a95e2d 100755 --- a/cli/worblehat.py +++ b/cli/worblehat.py @@ -7,8 +7,6 @@ import pgdb from fileformat import read_actionlist, write_actionlist from util import * -file_encoding = 'utf8' - # connection = pgdb.connect(database='oysteini_pbb2', # user='oysteini_pbb', # password='lio5Aide', @@ -215,7 +213,7 @@ def show(connection, ids, commit_format=False, tmp_file=False): else: output = '\n'.join(objects) if tmp_file: - filename = write_tmpfile('.'.join(ids), output, file_encoding) + filename = write_tmpfile('.'.join(ids), output) print filename return filename else: @@ -277,7 +275,15 @@ def search_book(connection, search_strings, search_description=False): def search_person(connection, search_strings): - pass + c = connection.cursor() + result_strings = [] + for s in search_strings: + for i in range(3): + result_strings.append(s) + c.execute('SELECT * FROM person LEFT JOIN bookperson ON person.id=bookperson.person WHERE person.lastname ILIKE %s or person.firstname ILIKE %s OR person.id ILIKE %s', result_strings) + for i in xrange(c.rowcount): + person = fetchone_dict(c) + print person['lastname'], ', ', person['firstname'], '\t', person['book'] def do_action(connection, action): print 'ACTION %s ' % action @@ -289,7 +295,7 @@ def do_action(connection, action): 'new-category': q_new_category, 'edit-category': q_edit_category} action_type = action['action'] - execute_query(c, queries[action_type], action) + c.execute(queries[action_type], action) if action_type in ['new-book', 'edit-book']: print 'FIXING PERSONS: REMOVING' c.execute(q_remove_bookpersons, {'isbn': action['isbn']}) @@ -329,10 +335,7 @@ def commit(connection, filename=None): commit_actions(connection, actions) def edit(connection, ids): - filename = show(connection, ids, commit_format=True, tmp_file=True) - print filename - run_editor(filename) - commit(connection, filename) + pass def map_cmd(connection, shelfname=None, category=None): pass