From 5c6223c1c52ab79ba3b941a79a51af98f51a6197 Mon Sep 17 00:00:00 2001 From: neslihan Date: Thu, 29 Jan 2026 14:04:37 +0100 Subject: [PATCH 1/5] first commit --- book.py | 32 ++++++++++++++++++++++++++++++++ library.py | 25 +++++++++++++++++++++++++ login_page.py | 43 +++++++++++++++++++++++++++++++++++++++++++ user.py | 17 +++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 book.py create mode 100644 library.py create mode 100644 login_page.py create mode 100644 user.py diff --git a/book.py b/book.py new file mode 100644 index 0000000..b8f9205 --- /dev/null +++ b/book.py @@ -0,0 +1,32 @@ +class Book(): + def __init__(self,title,author,publication_year,is_borrowed,borrowed_by): + self.title = title + self.author = author + self.pubication_year = publication_year + self.is_borrowed = is_borrowed + self.borrowed_by = borrowed_by + + def show_info(self): + print("Title", self.title) + return + + + def borrow(user): + pass + + def return_book(): + pass + + def to_dict(): + pass + + +class Novel(Book): + def __init__(self,title,author,publication_year,is_borrowed,borrowed_by,genre): + Book.__init__(self,title,author,publication_year,is_borrowed,borrowed_by) + self.genre = genre + +class Magazine(Novel): + def __init__(self,title,author,publication_year,is_borrowed,borrowed_by, issue) + Book.__init__(self,title,author,publication_year,is_borrowed,borrowed_by) + self.issue = issue \ No newline at end of file diff --git a/library.py b/library.py new file mode 100644 index 0000000..7aa526e --- /dev/null +++ b/library.py @@ -0,0 +1,25 @@ + + +class Library(): + def __init__(self,name,books,users): + self.name = name + self.books = books + self.users = users + + def add_book(book): + pass + + def add_user(user): + pass + + def show_all_books(): + pass + + def login(name,password): + print(name, password) + + def save(file): #save to json + pass + + def load(file): #load from json + pass \ No newline at end of file diff --git a/login_page.py b/login_page.py new file mode 100644 index 0000000..cbffb2b --- /dev/null +++ b/login_page.py @@ -0,0 +1,43 @@ +from library import Library + +while True: + + print("-" * 60) + print() + print(" 1- LOGIN ") + print(" 2- CREATE ACOUNT ") + print(" 3- EXIT. ") + print() + print("-" * 60) + + choice = input("Enter your choice please: ") + while True: + + if choice =="1": + name = input("Enter a name: ") + password = input("Enter a password: ") + Library.login(name,password) + + print("-" * 60) + print() + print(" 1- LIST ALL BOOKS ") + print(" 2- BORROW A BOOK ") + print(" 3- RETURN A BOOK ") + print(" 4- SHOW MY BORROWED BOOKS") + print(" 5- SAVE AND EXIT") + print() + print("-" * 60) + break + + if choice == 2: + Library.add_user(user) + + if choice == 3: + break + + + + + + + diff --git a/user.py b/user.py new file mode 100644 index 0000000..5bc87f1 --- /dev/null +++ b/user.py @@ -0,0 +1,17 @@ +class User(): + def __init__(self,name,password,borrowed_books) + self.name = name + self.password = password + self.boorwed_books = borrowed_books + + def borrow_book(book): + pass + + def return_book(book): + pass + + def list_borrowed_books(): + pass + + def to_dict(): + pass \ No newline at end of file From 3c38565e79f4d07694324b9a5627200814dc1042 Mon Sep 17 00:00:00 2001 From: canbaz Date: Thu, 29 Jan 2026 14:07:03 +0100 Subject: [PATCH 2/5] meaningless save --- book.py | 1 + 1 file changed, 1 insertion(+) diff --git a/book.py b/book.py index b8f9205..4fd0c65 100644 --- a/book.py +++ b/book.py @@ -12,6 +12,7 @@ def show_info(self): def borrow(user): + print(user) pass def return_book(): From 29712b959028dccfdc2b59d23beebe1f28a18be3 Mon Sep 17 00:00:00 2001 From: neslihan Date: Thu, 29 Jan 2026 14:10:33 +0100 Subject: [PATCH 3/5] random commit --- book.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book.py b/book.py index 4fd0c65..f1be282 100644 --- a/book.py +++ b/book.py @@ -12,7 +12,8 @@ def show_info(self): def borrow(user): - print(user) + # print(user) this is unncessary + pass def return_book(): From e0f8396d8c9932aa46cb71390bcb54a4f9425d90 Mon Sep 17 00:00:00 2001 From: neslihan Date: Sat, 31 Jan 2026 22:52:46 +0100 Subject: [PATCH 4/5] clean --- book.py | 34 ---------------------------------- library.py | 25 ------------------------- login_page.py | 43 ------------------------------------------- user.py | 17 ----------------- 4 files changed, 119 deletions(-) delete mode 100644 book.py delete mode 100644 library.py delete mode 100644 login_page.py delete mode 100644 user.py diff --git a/book.py b/book.py deleted file mode 100644 index f1be282..0000000 --- a/book.py +++ /dev/null @@ -1,34 +0,0 @@ -class Book(): - def __init__(self,title,author,publication_year,is_borrowed,borrowed_by): - self.title = title - self.author = author - self.pubication_year = publication_year - self.is_borrowed = is_borrowed - self.borrowed_by = borrowed_by - - def show_info(self): - print("Title", self.title) - return - - - def borrow(user): - # print(user) this is unncessary - - pass - - def return_book(): - pass - - def to_dict(): - pass - - -class Novel(Book): - def __init__(self,title,author,publication_year,is_borrowed,borrowed_by,genre): - Book.__init__(self,title,author,publication_year,is_borrowed,borrowed_by) - self.genre = genre - -class Magazine(Novel): - def __init__(self,title,author,publication_year,is_borrowed,borrowed_by, issue) - Book.__init__(self,title,author,publication_year,is_borrowed,borrowed_by) - self.issue = issue \ No newline at end of file diff --git a/library.py b/library.py deleted file mode 100644 index 7aa526e..0000000 --- a/library.py +++ /dev/null @@ -1,25 +0,0 @@ - - -class Library(): - def __init__(self,name,books,users): - self.name = name - self.books = books - self.users = users - - def add_book(book): - pass - - def add_user(user): - pass - - def show_all_books(): - pass - - def login(name,password): - print(name, password) - - def save(file): #save to json - pass - - def load(file): #load from json - pass \ No newline at end of file diff --git a/login_page.py b/login_page.py deleted file mode 100644 index cbffb2b..0000000 --- a/login_page.py +++ /dev/null @@ -1,43 +0,0 @@ -from library import Library - -while True: - - print("-" * 60) - print() - print(" 1- LOGIN ") - print(" 2- CREATE ACOUNT ") - print(" 3- EXIT. ") - print() - print("-" * 60) - - choice = input("Enter your choice please: ") - while True: - - if choice =="1": - name = input("Enter a name: ") - password = input("Enter a password: ") - Library.login(name,password) - - print("-" * 60) - print() - print(" 1- LIST ALL BOOKS ") - print(" 2- BORROW A BOOK ") - print(" 3- RETURN A BOOK ") - print(" 4- SHOW MY BORROWED BOOKS") - print(" 5- SAVE AND EXIT") - print() - print("-" * 60) - break - - if choice == 2: - Library.add_user(user) - - if choice == 3: - break - - - - - - - diff --git a/user.py b/user.py deleted file mode 100644 index 5bc87f1..0000000 --- a/user.py +++ /dev/null @@ -1,17 +0,0 @@ -class User(): - def __init__(self,name,password,borrowed_books) - self.name = name - self.password = password - self.boorwed_books = borrowed_books - - def borrow_book(book): - pass - - def return_book(book): - pass - - def list_borrowed_books(): - pass - - def to_dict(): - pass \ No newline at end of file From 7ff3b6975669333dd2235b89aa4f7f4df04a758b Mon Sep 17 00:00:00 2001 From: neslihan Date: Sat, 31 Jan 2026 23:02:45 +0100 Subject: [PATCH 5/5] team1-week3 --- book.py | 55 +++++++++++++++++++++++++++ library.json | 18 +++++++++ library.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++ login_page.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ user.py | 56 ++++++++++++++++++++++++++++ 5 files changed, 324 insertions(+) create mode 100644 book.py create mode 100644 library.json create mode 100644 library.py create mode 100644 login_page.py create mode 100644 user.py diff --git a/book.py b/book.py new file mode 100644 index 0000000..86280c9 --- /dev/null +++ b/book.py @@ -0,0 +1,55 @@ + + +class Book(): + def __init__(self,title,author,publication_year,is_borrowed,borrowed_by): + self.title = title + self.author = author + self.publication_year = publication_year + self.is_borrowed = is_borrowed + self.borrowed_by = borrowed_by + + def show_info(self): + print("Title: ",self.title) + print("Author: ",self.author) + print("Publication_year: ",self.publication_year) + print("Is borrowed: ",self.is_borrowed) + print("Borrowed by: ",self.borrowed_by) + + def borrow(self,user): + if self.is_borrowed==True: + print("The book was already borrowed by: ",self.borrowed_by) + else: + print("The book is available.") + self.is_borrowed = True # kitabı ödünç aldık + self.borrowed_by = user # kullanıcıyı atadık + print(f"{self.title} has been borrowed by {user}.") + + def return_book(self,): + if self.is_borrowed == False: + print("The book is not borrowed") + else: + user = self.borrowed_by + self.is_borrowed = False + self.borrowed_by = None + print(f"The book returned by: {user}") + + def to_dict(self): + return { + "title": self.title, + "author": self.author, + "publication_year": self.publication_year, + "is_borrowed": self.is_borrowed, + "borrowed_by": self.borrowed_by + } + + +class Novel(Book): + def __init__(self,title,author,publication_year,is_borrowed,borrowed_by,genre): + Book.__init__(self,title,author,publication_year,is_borrowed,borrowed_by) + self.genre = genre + +class Magazine(Book): + def __init__(self,title,author,publication_year,is_borrowed,borrowed_by, issue): + Book.__init__(self,title,author,publication_year,is_borrowed,borrowed_by) + self.issue = issue + diff --git a/library.json b/library.json new file mode 100644 index 0000000..6f54cb0 --- /dev/null +++ b/library.json @@ -0,0 +1,18 @@ +{ + "books": [ + { + "title": "Ada", + "author": "Ahmet", + "publication_year": 1900, + "is_borrowed": false, + "borrowed_by": null + } + ], + "users": [ + { + "name": "nesli", + "password": "123", + "borrowed_books": [] + } + ] +} \ No newline at end of file diff --git a/library.py b/library.py new file mode 100644 index 0000000..b390dc4 --- /dev/null +++ b/library.py @@ -0,0 +1,95 @@ +from book import Book +from user import User +import json +import os + +class Library(): + def __init__(self,name): + self.name = name + self.books = [] + self.users = [] + + def add_book(self,book): + for b in self.books: + if b.title == book.title: + print(f"The book '{book.title}' already exixsts!") + return + self.books.append(book) + print(f"The book '{book.title}' added to the library") + + def add_user(self,user): + for u in self.users: + if u.name == user.name: + print("User already exists!") + return + self.users.append(user) + print(f"User '{user.name}' added to the library!") + + def show_all_books(self): + for book in self.books: + print("-" * 40) + print("Title:",book.title) + print("Author:",book.author) + print("Available:", not book.is_borrowed) + print("Borrowed by:",book.borrowed_by) + print("-" * 40) + + def login(self,name,password): + for user in self.users: + if user.name == name and user.password == password: + return user + + print("user not found or password incorrect") + return None + + def borrow_book(self,user,title): + title = title.strip() + for book in self.books: + if book.title == title: + user.borrow_book(book) + return + print("Book not found") + + def return_book(self,user,title): + title = title.strip() + for book in self.books: + if book.title == title: + user.return_book(book) + return + print("Book not found.") + + def save(self,file): #save to json + book_list =[book.to_dict() for book in self.books] + user_list =[user.to_dict() for user in self.users] + data ={ + "books":book_list, + "users": user_list + } + with open(file, "w", encoding="utf-8") as f: + json.dump(data,f,ensure_ascii=False, indent=4) + + def load(self,file): #load from json + if not os.path.exists(file): + return + with open(file, "r", encoding="utf-8") as f: + data = json.load(f) + + self.books = [] + for book_data in data["books"]: + book = Book(**book_data) + self.books.append(book) + + self.users = [] + for user_data in data["users"]: + # Önce borrowed_books başlıklarını boş liste yap + borrowed_books_titles = user_data.pop("borrowed_books") + user = User(**user_data, borrowed_books=[]) # boş liste ile yarat + self.users.append(user) + + # Sonra borrowed_books listesini gerçek Book objeleri ile doldur + for title in borrowed_books_titles: + book = next((b for b in self.books if b.title == title), None) + if book: + user.borrowed_books.append(book) + book.is_borrowed = True + book.borrowed_by = user.name \ No newline at end of file diff --git a/login_page.py b/login_page.py new file mode 100644 index 0000000..d1ef1e0 --- /dev/null +++ b/login_page.py @@ -0,0 +1,100 @@ +from book import Book, Novel, Magazine +from user import User +from library import Library + +data_file = "library.json" + +library = Library("My Library") + +library.load(data_file) + +library.add_book(Book("Ada", "Ahmet", 1900, False, None)) + +current_user = None + + +while True: + + print("-" * 60) + print() + print(" 1- LOGIN ") + print(" 2- CREATE ACOUNT ") + print(" 3- EXIT. ") + print() + print("-" * 60) + + choice = input("Enter your choice please: ") + if choice =="1": + name = input("Enter a name: ") + password = input("Enter a password: ") + user = library.login(name,password) + + if user: + current_user = user + print(f"\nWelcome back, {current_user.name}!") + + while True: + print("-" * 60) + print() + print(" 1- LIST ALL BOOKS ") + print(" 2- BORROW A BOOK ") + print(" 3- RETURN A BOOK ") + print(" 4- SHOW MY BORROWED BOOKS") + print(" 5- SAVE AND EXIT") + print() + print("-" * 60) + + option = input("Enter your choice please: ") + + if option == "1": + library.show_all_books() + + elif option == "2": + title = input("Enter book title: ") + library.borrow_book(current_user, title) + + elif option == "3": + title = input("Enter book title: ") + library.return_book(current_user, title) + + elif option == "4": + current_user.list_borrowed_books() + + elif option == "5": + current_user = None + print("Logged out. Saving data...") + library.save(data_file) + break + + else: + print("Invalid option.") + + else: + print("Login failed.") + + elif choice == "2": + name = input("Enter a name: ") + password = input("Enter a password: ") + new_user = User(name,password,[]) + library.add_user(new_user) + print("Account created!") + + elif choice == "3": + library.save(data_file) + print("Data saved.") + break + + else: + print("Invalid choice!") + + + + +# def borrow_by_title(user, all_books, title): +# book_to_borrow = next((b for b in all_books if b.title == title), None) +# if book_to_borrow: +# user.borrow_book(book_to_borrow) +# else: +# print(f"Book '{title}' not found!") + + diff --git a/user.py b/user.py new file mode 100644 index 0000000..d87a44b --- /dev/null +++ b/user.py @@ -0,0 +1,56 @@ +from book import Book +import json + + + +class User(): + def __init__(self,name,password,borrowed_books): + self.name = name + self.password = password + self.borrowed_books = borrowed_books + + def borrow_book(self,book): + if book.is_borrowed == True: + print("The book was already borrowed.") + else: + book.borrow(self.name) + self.borrowed_books.append(book) + + def return_book(self,book): + if book not in self.borrowed_books: + print("You did not borrow this book.") + else: + book.return_book() + self.borrowed_books.remove(book) + + + def list_borrowed_books(self): + if not self.borrowed_books: + print("You have no borrowed books.") + else: + for book in self.borrowed_books: + print("title:", book.title, "|Author:" ,book.author ) + + + def to_dict(self): + return { + "name": self.name, + "password": self.password, + "borrowed_books": [book.title for book in self.borrowed_books] + } + + +# # Test için kullanıcı +# test_user = User("Ayşe", "123",[]) + +# # Örnek kitaplar +# all_books = [ +# Book("Ada", "Ahmet", 1900, False, None), +# Book("Deniz", "Mehmet", 1920, False, None) +# ] + +# # Ödünç alma testi +# #borrow_by_title(test_user, all_books, "Ada") # Tek satırla ödünç al + +# # Kullanıcının ödünç aldığı kitapları listele +# #test_user.list_borrowed_books()