Bottom Page

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
"""
 
Yoriz wrote Jun-14-2019, 06:24 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
Explain what you expect to happen and what is actually happening and any errors received in error tags.
also can the code be reduced to just the part in question.
Beginner_coder123 likes this post
Quote
#3
(Jun-14-2019, 06:30 PM)Yoriz Wrote: Explain what you expect to happen and what is actually happening and any errors received in error tags.
also can the code be reduced to just the part in question.

All done!
Quote
#4
You definitely didn't reduce it enough, if you did it at all. Most questions (including this one) can usually be reduced to 5-10 lines of code, you're far less likely to get a response with the literally hundreds of lines.
Yoriz likes this post
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#5
(Jun-14-2019, 11:27 PM)micseydel Wrote: You definitely didn't reduce it enough, if you did it at all. Most questions (including this one) can usually be reduced to 5-10 lines of code, you're far less likely to get a response with the literally hundreds of lines.

Okay, my bad. I changed it now
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Fixing arrays output in Python WLST script pkbash 2 375 Feb-28-2019, 06:20 PM
Last Post: pkbash
  Need help with fixing iteration counter Kapolt 8 738 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 738 Oct-17-2018, 03:26 AM
Last Post: stullis

Forum Jump:


Users browsing this thread: 1 Guest(s)