Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions library/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def add_book(filename, isbn, title, author):
# In the space below, write code that adds the key isbn
# and the value {'title':title, 'author':author}
# to the books object.

book['isbn'] = [{'student':student, 'book':book}, f]
# Finally, write code that writes the new data to the library
# Do we need to return anything?
pass
Expand All @@ -52,7 +52,8 @@ def remove_book(filename, isbn):

# How can we *remove* an item from a dictionary?
# Write code to delete the book keyed by isbn in the space below

if 'isbn' in remove_book:
del remove_book['isbn']
# Now write code that saves the new version of the data to your library
pass

Expand All @@ -62,7 +63,7 @@ def check_out(filename, isbn, s_id):

# Find a way to mark a book as checked out. Be sure to associate
# the book with the student who borrowed it!

f.__setitem__("filename",checked out)

# And again save the data here

Expand All @@ -71,7 +72,7 @@ def check_out(filename, isbn, s_id):

def return_book(filename, isbn):
students, books = open_library(filename)

# Now ensure that the book is no longer checked out and save the changes
# to the library.

Expand Down
88 changes: 88 additions & 0 deletions library/library/library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json


def open_library(filename):
# Create empty dictionaries just in case the library file is empty
students = {}
books = {}

# Open the library file encoded in JSON and load it into the data object
# We use the with keyword so we don't have to explicitly close the file
# later.
#
# Alternatively you could use:
#
# f = open(filename)
# data = json.load(f)
# f.close()
#
# and accomplish the same thing.

with open(filename) as f:
data = json.load(f)

# If there are students or books in the library,
# overwrite the empty dictionaries we created
if data['students'] != {}:
students = data['students']

if data['books'] != {}:
books = data['books']

# Return the data we loaded from the file
return students, books


def add_book(filename, isbn, title, author):
# Here's a start
students, books = open_library(filename)

# Now how can we add books to the data?
# In the space below, write code that adds the key isbn
# and the value {'title':title, 'author':author}
# to the books object.

# Finally, write code that writes the new data to the library
# Do we need to return anything?
pass


def remove_book(filename, isbn):
students, books = open_library(filename)

# How can we *remove* an item from a dictionary?
# Write code to delete the book keyed by isbn in the space below

# Now write code that saves the new version of the data to your library
pass


def check_out(filename, isbn, s_id):
students, books = open_library(filename)

# Find a way to mark a book as checked out. Be sure to associate
# the book with the student who borrowed it!


# And again save the data here

pass


def return_book(filename, isbn):
students, books = open_library(filename)

# Now ensure that the book is no longer checked out and save the changes
# to the library.

pass


def status(filename):
students, books = open_library(filename)
# Print out two lists - one of all books currently checked out,
# and one of all available books.

pass