def main(): year = int(input("Is there a game from (enter a year) or <press enter to skip>: ") or 1999) print("\n", reports.get_genres("game_stat.txt")) genre = input("Number of games from (enter a genre) or <press enter to skip>: ") or "RPG" print("\n", reports.sort_abc("game_stat.txt")) title = input("Line number of (enter a title) or <press enter to skip>: ") or "Minecraft" genre_list = reports.get_genres("game_stat.txt") title_list = reports.sort_abc("game_stat.txt") with open("report-results.txt", mode="w", encoding="UTF-8") as export_file: export_file.write("Game count: " + str(reports.count_games("game_stat.txt")) + "\n\n") export_file.write("Is there a game from " + str(year) + ": ") export_file.write(str(reports.decide("game_stat.txt", year)) + "\n\n") export_file.write("Latest game: " + str(reports.get_latest("game_stat.txt")) + "\n\n") export_file.write("Number of " + genre + " games: ") export_file.write(str(reports.count_by_genre("game_stat.txt", genre)) + "\n\n") export_file.write("Line number of " + title + ": ") export_file.write(str(reports.get_line_number_by_title("game_stat.txt", title)) + "\n\n") export_file.write("Ordered titles: \n") export_file.write("" .join(game + ", " for game in title_list if game != title_list[-1]) + title_list[-1] + "\n\n") # Puts a comma between each title before writing to the file export_file.write("Genres: ") export_file.write("" . join(genre + ", " for genre in genre_list if genre != genre_list[-1]) + genre_list[-1] + "\n\n") export_file.write("Release date of top-sold FPS: ") export_file.write(str(reports.when_was_top_sold_fps("game_stat.txt")) + "\n\n")
def print_get_genres(): genres = "" print("All the genres in the file: ", end="") for item in range(len((get_genres("game_stat.txt")))): genres += '"' + (get_genres("game_stat.txt"))[item] + '"' + ", " if item + 1 == len(get_genres("game_stat.txt")): genres = genres[:-2] genres += "." print(genres)
def export_get_genres(): with open("export.txt", "a") as file_handler: genres = "" file_handler.write("All the genres in the file: ") for item in range(len((get_genres("game_stat.txt")))): genres += '"' + (get_genres("game_stat.txt"))[item] + '"' + ", " if item + 1 == len(get_genres("game_stat.txt")): genres = genres[:-2] genres += "." file_handler.write(genres)
def printing(): fallback_file_name = "game_stat.txt" file_name = input("Which file should I analyze? (default: game_stat.txt) ") if not file_name: file_name = fallback_file_name try: file_name = check_file(file_name, fallback_file_name) except FileNotFoundError as e: print("No such file. Exiting...") else: print("1.", reports.count_games(file_name)) year = int(input("2. Which year? ")) print(" ", reports.decide(file_name, year)) print("3.", reports.get_latest(file_name)) genre = input("4. Which genre? ") print(" ", reports.count_by_genre(file_name, genre)) title = input("5. Which title? ") print(" ", reports.get_line_number_by_title(file_name, title)) # BONUS print("B-1. Sorted titles: ") for line in reports.sort_abc(file_name): print(" ", line) print("B-2. Genres:") for line in reports.get_genres(file_name): print(" ", line) print("B-3.", reports.when_was_top_sold_fps(file_name))
def process_question(question): if question == "How many games are in the file?": answer = reports.count_games(FILE_NAME) print(answer) elif question == "Is there a game from a given year?": year = input("Which year?") answer = reports.decide(FILE_NAME, year) print(answer) elif question == "Which is the latest game?": answer = reports.get_latest(FILE_NAME) print(answer) elif question == "How many games are in the file by genre?": genre = input("Provide a genre:") answer = reports.count_by_genre(FILE_NAME, genre) print(answer) elif question == "What is the line number of a given title?": title = input("Provide a title:") answer = reports.get_line_number_by_title(FILE_NAME, title) print(answer) elif question == "Can you give me the alphabetically ordered list of the titles?": print("Yes, sure.") answer = reports.sort_abc(FILE_NAME) print(answer) elif question == "Which genres occur in the data file?": answer = reports.get_genres(FILE_NAME) print(answer) elif question == "What is the release year of the top sold first-person shooter game?": answer = reports.when_was_top_sold_fps(FILE_NAME) print(answer)
def printing_get_genres(file_name): """prints set of the genres (alphabetical order)""" result = reports.get_genres(file_name) print ("The ordred list of genres:") for nr, genre in enumerate(result, 1): print (" ", nr, genre) print()
def main(file_name): # How many games are in the file? print_function("\nNumber of games in the file:", reports.count_games(file_name)) # bonus: What is the abc ordered list of titles? print_function("\nThese are the names of said games: ", reports.sort_abc(file_name)) # Which is the latest game? print_function("\nThe latest game in the file is:", reports.get_latest(file_name)) # What is the line number of the given title? try: print_function("The game's line number is: ", reports.get_line_number_by_title(file_name)) except ValueError: print("There's no game with that name in the file!") # Is there a game from a given year? print_function("There is at least one game from the given year:", reports.decide(file_name)) # bonus: What are the genres? print_function("\nThe following genres are in the file: ", reports.get_genres(file_name)) # How many games do we have by genre? print_function("Number of games in genre:", reports.count_by_genre(file_name)) # bonus: What is the release date of top sold fps shooter game? print_function("\nThe highest-selling RPG from the list was released in: ", reports.when_was_top_sold_fps(file_name))
def export_get_genres(): """Export to file: a list of all genres without duplicates.""" game_genres = reports.get_genres(filename) for genre in game_genres: export_to_file(genre + "\n") print("DATA TRANSFERRED TO A FILE: exported_answers.txt!\n")
def test_bonus_2_get_genres(self): result = reports.get_genres(self.input_file) expected_result = sorted(["Action-adventure", "First-person shooter", "Real-time strategy", "RPG", "Sandbox", "Simulation", "Survival game"]) self.assertEqual(result, expected_result)
def main(data_file): os.system('clear') exporter(export_name(), str(reports.count_games(data_file)), year_input(data_file), reports.get_latest(data_file), genre_input(data_file), title_input(data_file), str(reports.sort_abc(data_file)), str(reports.get_genres(data_file)), top_sold_handler(data_file)) print("Export was successfull!")
def print_the_answers(file_name, year, genre, title): print(reports.count_games(file_name)) print(reports.decide(file_name, year)) print(reports.get_latest(file_name)) print(reports.count_by_genre(file_name, genre)) print(reports.get_line_number_by_title(file_name, title)) print(reports.sort_abc(file_name)) print(reports.get_genres(file_name)) print(reports.when_was_top_sold_fps(file_name))
def main(): print(count_games()) print(decide("game_stat.txt", 2004)) print(get_latest()) print(count_by_genre()) print(get_line_number_by_title()) print(sort_abc()) print(get_genres()) print(when_was_top_sold_fps())
def main(): print("Every genre: ", reports.get_genres("game_stat.txt")) print("Number of genres: ", reports.count_by_genre("game_stat.txt", input("\nEnter a genre: ")), "\n") print("Number of games: ", reports.count_games("game_stat.txt")) print("Was a game released this year? ", reports.decide("game_stat.txt", input("\nEnter a year: ")), "\n") print("Every genre: \n", reports.get_genres("game_stat.txt")) print("\nLatest game: \n", reports.get_latest("game_stat.txt")) print( "Line number of given title: ", reports.get_line_number_by_title("game_stat.txt", input("\nEnter a title: ")), "\n") print("Games sorted by title: ", reports.sort_abc("game_stat.txt")) print("\nRelease date of top sold FPS: \n", reports.when_was_top_sold_fps("game_stat.txt"))
def printing_reports(): import reports print(reports.count_games("game_stat.txt")) print(reports.decide("game_stat.txt", "2012")) print(reports.get_latest("game_stat.txt")) print(reports.count_by_genre("game_stat.txt", "Real-time strategy")) print(reports.get_line_number_by_title("game_stat.txt", "Counter-Strike: Condition Zero")) print(reports.sort_abc("game_stat.txt")) print(reports.get_genres("game_stat.txt")) print(reports.when_was_top_sold_fps("game_stat.txt"))
def main(): print(reports.count_games("game_stat.txt"), reports.decide("game_stat.txt", 2012), reports.get_latest("game_stat.txt"), reports.count_by_genre("game_stat.txt", "RPG"), reports.get_line_number_by_title("game_stat.txt", "Diablo III"), reports.sort_abc("game_stat.txt"), reports.get_genres("game_stat.txt"), reports.when_was_top_sold_fps("game_stat.txt"), sep="\n")
def export_to_txt(file_name, year, genre, title, exp_file="answers.txt"): with open(exp_file, "w") as text_file: text_file.write("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}".format( str(reports.count_games(file_name)), str(reports.decide(file_name, year)), str(reports.get_latest(file_name)), str(reports.count_by_genre(file_name, genre)), str(reports.get_line_number_by_title(file_name, title)), str(reports.sort_abc(file_name)), str(reports.get_genres(file_name)), str(reports.when_was_top_sold_fps(file_name))))
def export(): fw = open("reports.txt", "w") fw.writelines([ str(r.count_games("game_stat.txt")) + "\n", str(r.decide("game_stat.txt", 2000)) + "\n", str(r.get_latest("game_stat.txt")) + "\n", str(r.count_by_genre("game_stat.txt", "Real-time strategy")) + "\n", str(r.get_line_number_by_title("game_stat.txt", "Minecraft")) + "\n", str(r.sort_abc("game_stat.txt")) + "\n", str(r.get_genres("game_stat.txt")) + "\n", str(r.when_was_top_sold_fps("game_stat.txt")) + "\n" ])
def get_answers(inputs): file_name, year, genre, title = inputs """Returns a single string for the file exporter""" answers = (str(reports.count_games(file_name)) + "\n" + str(reports.decide(file_name, year)) + "\n" + reports.get_latest(file_name) + "\n" + str(reports.count_by_genre(file_name, genre)) + "\n" + str(reports.get_line_number_by_title(file_name, title)) + "\n" + ", ".join(reports.sort_abc(file_name)) + "\n" + ", ".join(reports.get_genres(file_name)) + "\n" + str(reports.when_was_top_sold_fps(file_name)) + "\n") return answers
def export_reports_answers(file_name, title, year, genre, export_file="export_reports.txt"): file = open(export_file, "w") file.write("The number of games in the file: {}\n".format(reports.count_games(file_name))) file.write("There is a game from a given year: {}\n".format(reports.decide(file_name, year))) file.write("The latest game is: {}\n".format(reports.get_latest(file_name))) file.write("The number of games we have by the given genre: {}\n".format(reports.count_by_genre(file_name, genre))) file.write("The line number of the given game is: {}\n".format(reports.get_line_number_by_title(file_name, title))) file.write("The alphabetical ordered list of the titles is: {}\n".format(reports.sort_abc(file_name))) file.write("The genres are: {}\n".format(reports.get_genres(file_name))) file.write("The release date of the top sold First-person shooter game is: {}\n".format(reports.when_was_top_sold_fps(file_name))) file.close() return export_file
def export_the_reports(export_file_name, file_name, year, genre, title): results = [ reports.count_games(file_name), reports.decide(file_name, year), reports.get_latest(file_name), reports.count_by_genre(file_name, genre), reports.get_line_number_by_title(file_name, title), reports.sort_abc(file_name), reports.get_genres(file_name), reports.when_was_top_sold_fps(file_name) ] with open(export_file_name, "w") as export_file: for item in results: export_file.write("%s\n" % item)
def export_to_file(file_name="export.txt"): answers = [] answers.append(count_games()) answers.append(decide("game_stat.txt", 1998)) answers.append(get_latest()) answers.append(count_by_genre()) answers.append(get_line_number_by_title()) answers.append(sort_abc()) answers.append(get_genres()) answers.append(when_was_top_sold_fps()) with open(file_name, "w") as file_export: for i in answers: i = str(i) file_export.write(i) file_export.write("\n")
def export_report(file): filename = open("export_report.txt", "w") filename.write(str(reports.count_games(file)) + "\n") filename.write(str(reports.decide(file, 2005)) + "\n") filename.write(str(reports.get_latest(file)) + "\n") filename.write(str(reports.count_by_genre(file, "eh")) + "\n") filename.write( str(reports.get_line_number_by_title(file, "Diablo III")) + "\n") filename.write(str(reports.get_genres(file)) + "\n") filename.write(str(reports.get_most_played) + "\n") filename.write(str(reports.sum_sold("game_stat.txt")) + "\n") filename.write(str(reports.get_selling_avg("game_stat.txt")) + "\n") filename.write(str(reports.count_longest_title("game_stat.txt")) + "\n") filename.write(str(reports.get_date_avg("game_stat.txt")) + "\n") pass
def export_results(filename="results.txt"): with open(filename, "w") as export_file: export_file.write(str(reports.count_games("game_stat.txt")) + "\n") export_file.write(str(reports.decide("game_stat.txt", 1970)) + "\n") export_file.write(str(reports.get_latest("game_stat.txt")) + "\n") export_file.write( str(reports.count_by_genre("game_stat.txt", "Survival game")) + "\n") export_file.write( str( reports.get_line_number_by_title("game_stat.txt", "World of Warcraft")) + "\n") export_file.write(str(reports.sort_abc("game_stat.txt")) + "\n") export_file.write(str(reports.get_genres("game_stat.txt")) + "\n") export_file.write( str(reports.when_was_top_sold_fps("game_stat.txt")) + "\n")
def judy_answers(): file = open("game_stat_answers.txt", "w") file.write(str(reports.count_games("game_stat.txt"))) file.write("\n") file.write(str(reports.decide("game_stat.txt", "1999"))) file.write("\n") file.write(str(reports.get_latest("game_stat.txt"))) file.write("\n") file.write(str(reports.count_by_genre("game_stat.txt", "Real-time strategy"))) file.write("\n") file.write(str(reports.get_line_number_by_title("game_stat.txt", "Counter-Strike: Condition Zero"))) file.write("\n") file.write(str(reports.sort_abc("game_stat.txt"))) file.write("\n") file.write(str(reports.get_genres("game_stat.txt"))) file.write("\n")
def test_bonus_2_get_genres(self): result = reports.get_genres(self.input_file) expected_result = ["Action-adventure", "First-person shooter", "Real-time strategy", "RPG", "Sandbox", "Simulation", "Survival game"] correct = True self.assertEqual(len(result), len(expected_result)) if len(result) != len(expected_result): correct = False for i in range(0, min(len(result), len(expected_result))): self.assertEqual(result[i], expected_result[i]) if result[i] != expected_result[i]: correct = False if correct: print("Bonus function 'get_genres' is passed.")
def report(filename): savefile.write(str(reports.count_games(filename))) savefile.write('\n') savefile.write(str(reports.decide(filename, 2000))) savefile.write('\n') savefile.write(str(reports.get_latest(filename))) savefile.write('\n') savefile.write(str(reports.count_by_genre(filename, "First-person shooter"))) savefile.write('\n') savefile.write(str(reports.get_line_number_by_title(filename, "The Sims"))) savefile.write('\n') savefile.write(str(reports.sort_abc(filename))) savefile.write('\n') savefile.write(str(reports.get_genres(filename))) savefile.write('\n') savefile.write(str(reports.when_was_top_sold_fps(filename))) savefile.write('\n')
def test_bonus_2_get_genres(self): result = reports.get_genres(self.input_file) expected_result = sorted(["Action-adventure", "First-person shooter", "Real-time strategy", "RPG", "Sandbox", "Simulation", "Survival game"]) self.assertEqual(len(result), len(expected_result)) correct = len(result) == len(expected_result) sorted_result = sorted(result) self.assertEqual(sorted_result, expected_result) if sorted_result != expected_result: print("result of get_genres was: {res}".format(res=result)) correct = False if correct: print("Bonus function 'get_genres' is passed.")
def answers_prints_from_reports(file_name, year, genre, title): print("Number of games in the file: {}".format( reports.count_games(file_name))) print("The latest game is: {}".format(reports.get_latest(file_name))) print("The number of games we have by the given genre: {}".format( reports.count_by_genre(file_name, genre))) print("The line number of the given game is: {}".format( reports.get_line_number_by_title(file_name, title))) pp = pprint.PrettyPrinter(indent=1, compact=False) print("Alphabetical ordered list of the titles is: ") pp.pprint(reports.sort_abc(file_name)) print("Genres are: ") pp.pprint(reports.get_genres(file_name)) print("There is a game from a given year: {}".format( reports.decide(file_name, year))) print("The release date of the top sold FPS game is: {}".format( reports.when_was_top_sold_fps(file_name))) return
def main(): input_file = 'game_stat.txt' print(r.count_games(input_file), '\n') print(r.decide(input_file, 2000), '\n') print(r.get_latest(input_file), '\n') print(r.count_by_genre(input_file, 'First-person shooter'), '\n') print(r.get_line_number_by_title(input_file, 'Counter-Strike'), '\n') shoretd_titles = r.sort_abc(input_file) for title in shoretd_titles: print(title) print() genres = r.get_genres(input_file) for genre in genres: print(genre) print('\n' + str(r.when_was_top_sold_fps(input_file)))
def export(): fallback_file_name = "game_stat.txt" file_name = input("Which file should I analyze? (default: game_stat.txt) ") if not file_name: file_name = fallback_file_name try: file_name = check_file(file_name, fallback_file_name) except FileNotFoundError as e: print("No such file. Exiting...") else: year = int( input('2. "Is there a game from a given year?" Which year? ')) genre = input('4. "How many games do we have by genre?" Which genre? ') title = input( '5. "What is the line number of the given game (by title)?" Which title? ' ) open( "export.txt", 'w').close() # clearing export.txt if exists or creating it if not with open("export.txt", 'a') as export_file: export_file.write("1. question: " + str(reports.count_games(file_name)) + '\n') export_file.write("2. question: " + str(reports.decide(file_name, year)) + '\n') export_file.write("3. question: " + reports.get_latest(file_name) + '\n') export_file.write("4. question: " + str(reports.count_by_genre(file_name, genre)) + '\n') export_file.write( "5. question: " + str(reports.get_line_number_by_title(file_name, title)) + '\n') export_file.write("B-1. Sorted titles:" + '\n') for line in reports.sort_abc(file_name): export_file.write(" " + line + '\n') export_file.write("B-2. Genres:" + '\n') for line in reports.get_genres(file_name): export_file.write(" " + line + '\n') export_file.write("B-3. question: " + str(reports.when_was_top_sold_fps(file_name)) + '\n') print("Exported answers into export.txt")
import reports '''file_name = 'game_stat.txt' year = 2000 genre = "First-person shooter" title = "Counter-Strike"''' # uncomment for testing print(reports.count_games(file_name)) print(reports.decide(file_name, year)) print(reports.get_latest(file_name)) print(reports.count_by_genre(file_name, genre)) print(reports.get_line_number_by_title(file_name, title)) print(reports.sort_abc(file_name)) print(reports.get_genres(file_name)) print(reports.when_was_top_sold_fps(file_name))
import reports '''file_name = 'game_stat.txt' year = 2000 genre = "First-person shooter" title = "Counter-Strike"''' # uncomment for testing report = open("report.txt", "w") report.write(str(reports.count_games(file_name)) + "\n") report.write(str(reports.decide(file_name, year)) + "\n") report.write(str(reports.get_latest(file_name)) + "\n") report.write(str(reports.count_by_genre(file_name, genre)) + "\n") report.write(str(reports.get_line_number_by_title(file_name, title)) + "\n") report.write(str(reports.sort_abc(file_name)) + "\n") report.write(str(reports.get_genres(file_name)) + "\n") report.write(str(reports.when_was_top_sold_fps(file_name)) + "\n") report.close()