Advertisement
ksieradzinski

Untitled

Feb 27th, 2025
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. import argparse
  2. import operations
  3.  
  4. parser = argparse.ArgumentParser(prog="Półka z książkami", description="Aplikacja do zarządzania zbiorem książek.")
  5. parser.add_argument("--install", action="store_true")
  6. parser.add_argument('--add-author', help="Imię i nazwisko autora rozdzielone spacją.")
  7. parser.add_argument('--list-authors', action="store_true", help="Wypisuje wszystkich autorów.")
  8. parser.add_argument('--add-book', nargs=2, metavar=("TYTUL", "AUTOR"), help="Dodaje książkę i autora")
  9. parser.add_argument('--list-books', action="store_true", help="Wypisuje wszystkie książki.")
  10. arguments = parser.parse_args()
  11.  
  12. if arguments.install:
  13.     operations.create_tables()
  14.  
  15. if arguments.add_author:
  16.     operations.add_author(arguments.add_author)
  17.  
  18. if arguments.list_authors:
  19.     for author in operations.list_authors():
  20.         print(author)
  21.  
  22. if arguments.add_book:
  23.     title, author = arguments.add_book
  24.     operations.add_book(
  25.         title=title,
  26.         author=author
  27.     )
  28.  
  29. if arguments.list_books:
  30.     books = {}
  31.     for row in operations.list_books():
  32.         if (row['first_name'], row['last_name']) not in books:
  33.             books[(row['first_name'], row['last_name'])] = []
  34.  
  35.         books[(row['first_name'], row['last_name'])].append(row['title'])
  36.  
  37.     for first_name, last_name in books:
  38.         print(first_name, last_name)
  39.  
  40.         for title in books[(first_name, last_name)]:
  41.             print(f" - {title}")
  42.  
  43.  
  44.     #
  45. # Dodaj do aplikacji pobieranie książek wraz z autorami
  46. # Wykorzystaj zapytanie SQL, które znajduje się na chacie.
  47. # Format wyniku powinien wygądać tak:
  48. # Jan Kochowski:
  49. # - Treny
  50. # - Fraszki
  51. # Henryk Sienkiewicz:
  52. # - W pusty...
  53. # - Quo Vadis..
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement