def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() game1 = json_data["Game 1"] #print(game1["Year"]) game2 = json_data["Game 2"] game3 = json_data["Game 3"] #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library game_name1 = game1["title"] game_year1 = game1["Year"] platform1 = game1["platform"] for elem in platform1: platform_name1 = elem["name"] platform_year1 = elem["launch year"] game_name2 = game2["title"] game_year2 = game2["Year"] platform2 = game2["platform"] for elem in platform2: platform_name2 = elem["name"] platform_year2 = elem["launch year"] game_name3 = game3["title"] game_year3 = game3["Year"] platform3 = game3["platform"] for elem in platform3: platform_name3 = elem["name"] platform_year3 = elem["launch year"] game1_platform = test_data.Platform(platform_name1, platform_year1) game1_data = test_data.Game(game_name1, game1_platform, game_year1) game2_platform = test_data.Platform(platform_name2, platform_year2) game2_data = test_data.Game(game_name2, game2_platform, game_year2) game3_platform = test_data.Platform(platform_name3, platform_year3) game3_data = test_data.Game(game_name3, game3_platform, game_year3) game_library.add_game(game1_data) game_library.add_game(game2_data) game_library.add_game(game3_data) #Return the completed game_library return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library for game_name in json_data: game_data = json_data[game_name] # Make a new game game = test_data.Game() # Get data from current game game.title = game_data["title"] game.year = game_data["year"] platform = game_data["platform"] launch_year = platform["launch year"] name = platform["name"] new_platform = test_data.Platform(launch_year, name) game.platform = new_platform game_library.add_game(game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() game_library.game = json_data["games"] for game_data in json_data["games"]: game = test_data.Game() game.title = game_data["Title"] game.year = game_data["Year"] for platform_stuff in game_data: game.platform = test_data.Platform() game.platform.name = platform_stuff[1] game.platform.launch_year = platform_stuff[0] game_library.add_game(game) ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data with open(json_data, 'r') as f: jsonData = json.load(f) # making Platform objects platformList = [] for i in range(0, len(jsonData["Game Library"])): platformList.append( test_data.Platform( jsonData["Game Library"][i]["Platform"]["Platform Name"], jsonData["Game Library"][i]["Platform"]["Launch Year"])) # making Game objects gameList = [] for i in range(0, len(jsonData["Game Library"])): gameList.append( test_data.Game(jsonData["Game Library"][i]["Title"], platformList[i], jsonData["Game Library"][i]["Year"])) # adding game objects to Game Library game_library.add_game(gameList[0]) game_library.add_game(gameList[1]) game_library.add_game(gameList[2]) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library ### End Add Code Here ### for game in data1: title = game["name"] year = game["Years"] platform_launchyear = game["platform"]["launch_year"] platform_name = game["platform"]["name"] new_platform = test_data.Platform(platform_name, platform_launchyear) new_game = test_data.Game(title, new_platform, year) game_library.add_game(new_game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() games = json_data["games"] for game in games: platform = test_data.Platform(game["platform"]["name"], game["platform"]["launch year"]) element = test_data.Game(game["title"], platform, game["year"]) game_library.add_game(element) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() games = json_data["games"] for game in games: platform = game["platform"] new_platform = test_data.Platform(platform["name"], platform["launchYear"]) new_game = test_data.Game(game["title"], new_platform, game["year"]) game_library.add_game(new_game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### for game in json_data: plat = test_data.Platform(game["platform"]["name"], game["platform"]["launch_year"]) new_game = test_data.Game(game["title"], plat, game["year"]) game_library.add_game(new_game) ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): # Initialize a new GameLibrary game_library = test_data.GameLibrary() # Loop through the json_data for game in json_data: new_game = test_data.Game() # title new_game.title = game["title"] # year new_game.year = game["year"] # platform (which requires reading name and launch_year) new_game.platform = test_data.Platform(game["platform"]["name"], game["platform"]["launch_year"]) # Add that Game object to the game_library game_library.add_game(new_game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() with open(json_data, "r") as reader: json_data = json.load(reader) for item in json_data: game = test_data.Game() game.title = item["title"] game.year = item["year"] # nested platform dictionary # flatten the dict into object attributes game.platform = test_data.Platform() game.platform.launch_year = item["platform"]["launch_year"] game.platform.name = item["platform"]["name"] game_library.add_game(game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### # Loop through the json_data games = json_data["games"] for game in games: #Create a new Game object from the json_data by reading new_platform = test_data.Platform(game["platform"]["name"], game["platform"]["launch_year"]) new_game = test_data.Game(game["title"], new_platform, game["year"]) # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library game_library.add_game(new_game) ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() # Get the games array by looping through the the JSON data games = test_json_data["games"] # Iterate through the games array for game in games: # Create a new platform object with the "platform name" and "launch year" new_platform = test_data.Platform(game["platform name"], game["launch year"]) # Create a new Game object by reading the title, the new_platform object, and the year new_game = test_data.Game(game["title"], new_platform, game["year"]) # Add the Game object to the game_library game_library.add_game(new_game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() for entry in json_data: title = entry["title"] year = entry["Year"] platform = test_data.Platform(entry["platform"]["name"], entry["platform"]["launch year"]) game = test_data.Game(title, platform, year) game_library.add_game(game) #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library #Return the completed game_library return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library for g in json_data["games"]: p = g['platform'] platform = test_data.Platform(p['name'], p['launch year']) game = test_data.Game(g['title'], platform, g['year']) game_library.add_game(game) ### End Add Code Here ### return game_library
def make_game_library_from_json( json_data ): #Initialize a new GameLibrary with open(json_data) as reader: data = json.load(reader) test = open(json_data) #print(test.read()) #use data object to build a new game library game_library = test_data.GameLibrary() a = json.load(test) for game_json in json_data: new_game = test_data.Game() new_game.title = game_json["title"] new_game.year = game_json[-1] platform_json = game_json["platform"] new_platform = test_data.Platform() new_platform.launch_year = platform_json[-1] new_platform.name = platform_json["name"] new_game.platform = new_platform game_library.add_game(new_game) #print(game_library.games) ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library ### End Add Code Here ### return game_library json_data = "data/test_data.json" game_library = make_game_library_from_json(a) print(game_library)
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library ### End Add Code Here ### for x in json_data["games"]: platform = test_data.Platform(x["platform"]["name"], x["platform"]["launch year"]) game = test_data.Game(x["title"], platform, x["year"]) game_library.add_game(game) return game_library
def make_game_library_from_json( json_data ): #Initialize a new GameLibrary game_library = test_data.GameLibrary() for game in json_data: gamenum = json_data[game] plat = gamenum["platform"] for i in plat: newplat = test_data.Platform(plat["name"], plat["launch year"]) new_game = test_data.Game(title=gamenum["title"], platform=newplat,year=gamenum["Year"]) game_library.add_game(new_game) ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading for game_data in json_data["Games"]: # The loop steps through each element in the list (here the list is kids_data) # and the variable kid_data represents the current element in the list #Make a new Kid game = test_data.Game() platform_json = game_data["Platform"] game.title = game_data["Title"] game.year = game_data["Year"] new_platform = test_data.Platform() new_platform.launch_year = platform_json["Year"] new_platform.name = platform_json["Name"] #Add that Game object to the game_library game_library.add_game(game) game.platform = new_platform ### End Add Code Here ### return (game_library)
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data for game_data in json_data["games"]: #Create a new Game object from the json_data by reading game = test_data.Game() # title game.title = game_data["title"] # year game.year = game_data["year"] # platform (which requires reading name and launch_year) game.platform = test_data.Platform() game.platform.name = game_data["platform"]["name"] game.platform.launch_year = game_data["platform"]["launch year"] #Add that Game object to the game_library game_library.add_game(game) ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() ### Begin Add Code Here ### #Loop through the json_data for single_game_info in json_data: #Create a new Game object from the json_data by reading # title title = single_game_info['title'] # year year = single_game_info['year'] # platform (which requires reading name and launch_year) platform_name = single_game_info['platform']['name'] platform_launch_year = single_game_info['platform']['launch year'] platform = test_data.Platform(platform_name, platform_launch_year) #Add that Game object to the game_library game = test_data.Game(title, platform, year) game_library.add_game(game) ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() for game in json_data: game_object = test_data.Game() game_object.title = game["title"] game_object.year = game["Year"] platform_object = test_data.Platform() platform_object.name = game["platform"]["name"] platform_object.launch_year = game["platform"]["launch year"] game_object.platform = platform_object game_library.add_game(game_object) ### Begin Add Code Here ### #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library ### End Add Code Here ### return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library #Return the completed game_library # print (json_data) # loops through json data list under the key games for data in json_data["games"]: # print(data) platform = test_data.Platform(data["platform"]["name"], data["platform"]["launch year"]) game = test_data.Game(data["title"], platform, data["year"]) game_library.add_game(game) return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() # Iterates through each game within json_data for key in json_data: # Establish the data for the current game game_data = json_data[key] # Getting game information new_game = test_data.Game() new_game.title = game_data["title"] new_game.year = game_data["Year"] # Getting platform information new_platform = test_data.Platform() platform_data = game_data["platform"] new_platform.launch_year = platform_data["launch year"] new_platform.name = platform_data["name"] new_game.platform = new_platform game_library.add_game(new_game) return game_library
def make_game_library_from_json(json_data): json_data = open("data/test_data.json").read() parsed_json = json.loads(json_data) #Initialize a new GameLibrary game_library = test_data.GameLibrary() #Loop through the json_data for game in parsed_json: addPlatform = test_data.Platform( parsed_json[game]["platform"]["name"], parsed_json[game]["platform"]["launch year"]) addGame = test_data.Game(parsed_json[game]["title"], addPlatform, parsed_json[game]["year"]) game_library.add_game(addGame) #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library #Return the completed game_library return game_library
def make_game_library_from_json(json_data): #Initialize a new GameLibrary game_library = test_data.GameLibrary() test_games = json_data["games"] for test_game in test_games: platform = test_game["platform"] launch_year = platform["launch year"] name = platform["name"] game_title = test_game["title"] game_year = test_game["Year"] new_platform = test_data.Platform(name, launch_year) new_game = test_data.Game(game_title, new_platform, game_year) game_library.add_game(new_game) #Loop through the json_data #Create a new Game object from the json_data by reading # title # year # platform (which requires reading name and launch_year) #Add that Game object to the game_library #Return the completed game_library return game_library
def make_game_library_from_json( json_data ): game_library = test_data.GameLibrary() # Initialize a new GameLibrary json_file_name = "test_data.json" with open(json_file_name, 'r') as reader: game_json_data = json.load(reader) ### Begin Add Code Here ### #Loop through the json_data #use for loop, not while loop #Create a new Game object from the json_data by reading # title # year # platform for x in range(0, 3): game_title = game_json_data["title"][x] game_year = game_json_data["year"][x] game_plat_year = game_json_data["platform"][x]["launch_year"] game_plat_name = game_json_data["platform"][x]["name"] game_platform = test_data.Platform(game_plat_name, game_plat_year) new_game = test_data.Game(game_title, game_platform, game_year) game_library.add_game(new_game) #create game object #Add that Game object to the game_library ### End Add Code Here ### return game_library