from common import document from common import flaf_db from common import flaf_tracer from common import flaf_types from common import list_dao from common import util cgitb.enable() tracer = flaf_tracer.Tracer('WordMapAction') form = cgi.FieldStorage() bookIdsString = form.getvalue('bookIds') bookIds = map(int, bookIdsString.split(',')) if bookIdsString else None listId = form.getvalue('listId') conn = flaf_db.newConn() dbDao = flaf_db.DbDao(conn) cursor = conn.cursor() if listId is not None: listDao = list_dao.ListDao(conn) bookIds = listDao.getBooksInList(listId) util.dieIfNone(bookIds, 'No book ids specified.') # tracer.log('Looking for [%s] in book %s' % (word, bookId)) data = { 'bookIds': bookIds, 'allBooks': dbDao.getAllBooks(),
parser = argparse.ArgumentParser( description='Tool for indexing/reindexing books.') parser.add_argument('action', help='The action to take.') parser.add_argument('--book_id', help='The book to index.', type=int, dest='bookId') parser.add_argument('--author', help='The author of the book to add.') parser.add_argument('--title', help='The title of the book to add.') parser.add_argument('--text_path', help='The path of the book to add.', dest='textPath') args = parser.parse_args() indexer = flaf_indexer.Indexer(flaf_db.newConn()) if args.action == 'delete': if args.bookId is None: print('Error: --book_id must be set to delete.') sys.exit(1) indexer.deleteFromIndexes(args.bookId, deleteFromBooks=True) if args.action == 'reindex': if args.bookId is None: print('Error: --book_id must be set to reindex.') sys.exit(1) indexer.deleteFromIndexes(args.bookId) indexer.addToIndexes(args.bookId)
from common import flaf_db from common import list_dao from common import colors parser = argparse.ArgumentParser( description='Tool manipulating lists of books.') parser.add_argument('action', help='Options: create, add, delete') parser.add_argument('--book_ids', help='Comma-delimited list of book ids to add/remove.', dest="bookIds") parser.add_argument('--label', help='Label of the list to use.', dest="label") args = parser.parse_args() listDao = list_dao.ListDao(flaf_db.newConn()) if args.action == 'create': label = util.requireFlag(args, 'label') util.dieIfNotNone(listDao.getListId(label), 'Cannot create list [%s], list already exists.' % label) listDao.createList(label) if args.action == 'delete': label = util.requireFlag(args, 'label') listId = listDao.getListId(label) util.dieIfNone(listId, 'Cannot delete list [%s], list does not exist.' % label) listDao.deleteList(label)
#!/usr/bin/python import sys import cgi, cgitb import json from common import flaf_db from common import document from common import flaf_tracer cgitb.enable() dbDao = flaf_db.DbDao(flaf_db.newConn()) form = cgi.FieldStorage() action = form.getvalue('action') or 'position' if action == 'position': ''' Ajax action for getting the context around one or more positions. Expects: positions Comma-delimited list of positions beforeCount How many words before the position to read afterCount How many words after the position to read Returns: Array of context objects (see flaf_types) ''' tracer = flaf_tracer.Tracer('getcontext/position') positions = map(int, form.getvalue('positions').split(',')) numBefore = int(form.getvalue('beforeCount')) numAfter = int(form.getvalue('afterCount')) bookId = int(form.getvalue('bookId'))