def load_Database(): #loads the database's list from a text file and returns the list nameHandle = open( r"C:\Users\DELL\Documents\Computer Science\Projects\Animal-Database-(Electron)\python-src\Animal_Database.txt", "r") animal_list = [] for line in nameHandle: animal = ast.literal_eval( line) #converts the string containing a single list to a list animal_info = animal[1] obj = Animal( animal[0]) #creates an entry based on the information in the array #adding all the information to the animal object obj.add_Range(animal_info[1]) obj.add_Class(animal_info[2]) obj.add_Diet(animal_info[3]) obj.add_Status(animal_info[4]) obj.add_Image(animal_info[5]) animal_list.append(obj) #adds the Animal object to the list return animal_list
def creating_animal(): #recieving the data data = request.get_json() #sending response to notify whether creating new entry was successful res = make_response(jsonify(animal_list.check_Animal(data[0]))) if animal_list.check_Animal(data[0]): #checking if entry is not a duplicate new_animal = Animal(data[0]) #creating new animal object #adding in all the information new_animal.add_Diet(data[1]) new_animal.add_Class(data[2]) new_animal.add_Status(data[3]) new_animal.add_Range(data[4]) new_animal.add_Image(data[5]) animal_list.add_Animal(new_animal) #adding new animal object to the list #updates the map and piechart data Data.update_MapData(data[4], "add") Data.update_DietData(data[1], "add") Data.update_ClassData(data[2], "add") Data.update_StatusData(data[3], "add") #saves the current database list exit() return res