Esempio n. 1
0
def booksByAuthor():
    author = selectAuthor()
    results = query.query(['title'], 'book', where=('author = "%s" ' % author))

    # only display the list if the list isn't empty; otherwise, return an error
    if len(results) > 0:
        print "\nHere are all of the books by %s :" % author
        query.print_results(results, ['title'])
    else:
        print "No books by this author are in the system."
Esempio n. 2
0
def availableCopiesOfBook():
    book_id = selectBook()
    results = getAvailableCopies(book_id)

    # only display the list if the list isn't empty; otherwise, return an error
    if len(results) > 0:
        print "There are %d copies of this book available. \nThey can be found at the following locations: " % len(
            results)
        query.print_results(results, ['copy_id', 'library_name'])
    else:
        print "No copies of this book are currently available."
Esempio n. 3
0
def checkoutCopy():
    book_id = selectBook()
    results = getAvailableCopies(book_id)
    if len(results) == 0:
        print "No available copies of this book. Sorry"
        return
    query.print_results(results, ['copy_id', 'library_name'])
    copy_id = input("Enter copy id of copy you would like to check out: ")
    member_id = selectMember()
    date = raw_input("Enter checkout date (YYYY-MM-DD): ")
    query.checkout_copy(librarian_id, copy_id, member_id, date)
    print "Book checked out!"
Esempio n. 4
0
def copiesPerLibrary():
    library = selectLibrary()
    results = query.query(['COUNT(*)'],
                          'copy',
                          where=('library_id = %d ' % library),
                          groupby='library_id')

    # only display the list if the list isn't empty; otherwise, return an error
    if len(results) > 0:
        print "\nHere is the current total of books at the requested library:"
        query.print_results(results, ['Total # of Books'])
    else:
        print "Error!"
Esempio n. 5
0
def checkinCopy():
    title = raw_input("What is the title of this book? ")
    results = query.query(
        ['copy_id', 'title', 'author'],
        'copy JOIN book USING (book_id) JOIN checkout USING (copy_id)',
        where="title LIKE '%" + title + "%' AND checkin_date is NULL")
    if len(results) == 0:
        print "No matching books checked out."
        return
    query.print_results(results, ['copy_id', 'title', 'author'])
    copy_id = input("Enter copy id of copy you would like to check in: ")
    date = raw_input("Enter checkin date (YYYY-MM-DD): ")
    query.checkin_copy(copy_id, date)
    print "Book checked in!"
Esempio n. 6
0
def removeCopy():
    title = raw_input("What is the title of this book? ")
    author = raw_input("Who is the author? ")
    results = query.query(
        ['copy_id', 'library_name', 'title', 'author'],
        'book JOIN copy USING (book_id) JOIN library USING (library_id)',
        where="author LIKE '%" + author + "%' AND title LIKE '%" + title +
        "%' ")
    if len(results) == 0:
        print "No copies of such a book found."
        return
    query.print_results(results,
                        ['copy_id', 'library_name', 'title', 'author'])
    copy_id = input("Enter copy id: ")
    query.delete_copy(copy_id)
    print "Copy deleted!"
Esempio n. 7
0
def addCopy():
    title = raw_input("What is the title of this book? ")
    author = raw_input("Who is the author? ")
    library_id = selectLibrary()
    results = query.query(['book_id', 'title', 'author'],
                          'book',
                          where="author LIKE '%" + author +
                          "%' AND title LIKE '%" + title + "%' ")
    if len(results) > 0:
        query.print_results(results, ['book_id', 'title', 'author'])
        copy = raw_input(
            "Do you want to add a copy of one of these book(s)? (y/n)")
        if copy == 'y':
            book_id = input("Enter book id: ")
            query.add_copy(book_id, library_id)
            print "Copy added!"
            return
    book_id = query.add_book(title, author)
    query.add_copy(book_id, library_id)
    print "Book created and copy added!"
Esempio n. 8
0
             try:
                 parser.parse_args(['--help'])
             except SystemExit:
                 continue
         elif response == 'flask':
             app.run(debug=False)
         else:
             try:
                 args = parser.parse_args(response.split(' '))
             except:
                 print("invalid input detected please retry")
                 continue
             if parser.error_message:
                 print(parser.error_message)
                 parser.error_message = ''
                 continue
             if args.linechart:
                 draw_line_chart(args, data_base_path)
             else:
                 result, error = process_query(args, data_base_path)
                 if error:
                     print(error)
                     continue
                 if args.bar:
                     draw_bar_chart(result, args)
                 else:
                     if len(result) > 0:
                         print_results(result, args)
                     else:
                         print("No records found")
 print("Bye!")