Python Forum
Fixing my backup function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fixing my backup function
#1
Hello everyone, I'm trying to fix some methods such as "restore a backup" in my public library system.. But I've been stuck for weeks. Can someone help me out? The code is below, but it's a lot. Not that complicated to read, I hope. I basically expect to be able to make a book, and put it in my JSON file. I already have an existing JSON file, but it doesn't append it to file. But instead it keeps it in the dictionary I made it in, and when I run the "make backup" method, it appends it in my backed up file. How can I make it so that you can add a book straight into the JSON file that's being loaded? That is booklist.json
"""TODO:
Done - filling the system with books from a file of books in JSON format (file with books).  You may add a fake ISBN number to book items and generate the number of book items per book.
Done - filling the system with customers from a file of people ( file).
Done - adding a book item.
Done - adding a customer.
Done - searching a book.
Done - making a book loan.
Done - making a backup of the system in JSON format.
Not Done - restoring the system from a backup.
 """
 
 
import json
import csv
 
"""
    Created class 'Book' for adding a new book,
    Returning the new dict() back to the class 'bookItems'
    where it will be added to the bookcollection
"""
 
class Book:
    @staticmethod
    def createBook(FileBookcollection):
        #parameters is for the inputUser. So it shows the right text for the user
        parameters = ["author","country","imageLink","language","link","pages","title","year"]
        newBook = dict()
        for item in parameters:
            inputUser = input("Fill in the " + item + " of the book: ")
            if inputUser == "":
                newBook[item] = None
            else:
                #adding the parameters as key and inputUser as value to the dict newBook
                newBook[item] = inputUser
        #Adding ISBN to the Dict with a counter that counts the Len(Dict) + 1
        newBook["ISBN"] = str(len(FileBookcollection) + 1)
        return newBook
 
 

    def restoreBooksBackup(this):
        with open(r".\bookCollectionBackup.json") as jsonFile:
            bookList = json.load(jsonFile)
            this.JSONFileBookCollection = bookList

    def makeBackup(this):
        with open(r".\backupFakeNames.csv","w",newline="") as output:
            new_csv = csv.writer(output)
            new_csv.writerows(this.allPersonsInfo)
 
        with open(r".\bookCollectionBackup.json","w") as jsonFile:
            json.dump(this.bookCollection.getAllBooks(),jsonFile)
 
        with open(r".\loanbookListBackup.json","w") as jsonFile:
            json.dump(this.loanBookList,jsonFile)
 
    def restoreBackUp(this):
        pass
"""
        with open(r".\bookCollectionBackup.json") as jsonFile:
            bookList = json.load(jsonFile)
            this.bookCollection.dumbJSON.JSONFileBookCollection = bookList
        with open(r".\backupFakeNames.csv","r") as output:
            new_csv = csv.reader(output)
            totalPersonListBackup = []
            for line in new_csv:
                totalPersonListBackup.append(line)
        this.AllCustomers.allPersonsInfo.personsList = totalPersonListBackup
        #this.bookCollection.restoreBooksBackup()
        with open(r".\loanbookListBackup.json") as jsonFile:
            fileLoanBookBackup = json.load(jsonFile)
        this.loanBookList = fileLoanBookBackup
"""
 
Reply


Messages In This Thread
Fixing my backup function - by Beginner_coder123 - Jun-14-2019, 06:22 PM
RE: Fixing my backup function - by Yoriz - Jun-14-2019, 06:30 PM
RE: Fixing my backup function - by micseydel - Jun-14-2019, 11:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  fixing error TypeError: 'float' object is not subscriptable programmingirl 1 1,531 Jan-28-2023, 08:13 PM
Last Post: deanhystad
  Need help fixing Index Error adesimone 1 1,313 Nov-21-2022, 07:03 PM
Last Post: deanhystad
  Fixing arrays output in Python WLST script pkbash 2 4,012 Feb-28-2019, 06:20 PM
Last Post: pkbash
  Need help with fixing iteration counter Kapolt 8 4,711 Oct-18-2018, 07:56 PM
Last Post: buran
  i need help in fixing my scientific calculator coding : (, im using python 3.5.5 hans77 1 4,180 Oct-17-2018, 03:26 AM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020