Advertisement
MateuszGrabarczyk

BookDB

Mar 29th, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from LibrarySystem.scr.Book import *
  2.  
  3.  
  4. class BookDB:
  5. book_list = []
  6.  
  7. def readFromBooksTxt(self):
  8. """
  9. Function to read from books.txt
  10. """
  11. with open("books.txt", "r", encoding="windows-1250") as f:
  12. for line in f:
  13. data = line.strip().split(';')
  14. try:
  15. book = Book(data[0], data[1], data[2], data[3], data[4])
  16. self.book_list.append(book)
  17. except:
  18. pass
  19.  
  20. def writeToBooksTxt(self):
  21. with open("books.txt", "w", encoding="windows-1250") as f:
  22. for b in self.book_list:
  23. f.write("{};{};{};{};{};{}".format(b.id, b.author, b.publication_year, b.title, b.rating, b.is_issued))
  24. f.write("\n")
  25.  
  26. def print_books(self):
  27. for book in self.book_list:
  28. print("{} by {}".format(book.title, book.author))
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement