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_sort_abc(): items = "" print("The titles in this file in alphabetical order are as follows:\n", end="") for item in range(len((sort_abc("game_stat.txt")))): items += '"' + (sort_abc("game_stat.txt"))[item] + '"' + ", " if item + 1 == len(sort_abc("game_stat.txt")): items = items[:-2] items += "." print(items)
def export_sort_abc(): with open("export.txt", "a") as file_handler: items = "" file_handler.write( "The titles in this file in alphabetical order are as follows:\n") for item in range(len((sort_abc("game_stat.txt")))): items += '"' + (sort_abc("game_stat.txt"))[item] + '"' + ", " if item + 1 == len(sort_abc("game_stat.txt")): items = items[:-2] items += "." file_handler.write(items + "\n\n")
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_sort_abc(file_name): """prints alphabetical ordered list of the titles""" result = reports.sort_abc(file_name) print ("The ordred list of titles:") for nr, game in enumerate(result, 1): print (" ", nr, game) 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 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 export_sort_abc(): """Export to file: titles of games in alphabetical order.""" sorted_games = reports.sort_abc(filename) print("List of games in alphabetical order: ") for game_title in sorted_games: export_to_file(game_title + "\n") print("DATA TRANSFERRED TO A FILE: exported_answers.txt!\n")
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(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 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 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 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 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_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 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 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 test_bonus_1_sort_abc(self): result = reports.sort_abc(self.input_file) expected_result = get_sorted() 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 'sort_abc' 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 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(): 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 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")
def print_results(): print(reports.count_games(open_file('game_stat.txt'))) print(reports.decide(open_file('game_stat.txt'), 1999)) print(reports.get_latest(open_file('game_stat.txt'))) print( reports.count_by_genre(open_file('game_stat.txt'), 'First-person shooter')) print( reports.get_line_number_by_title(open_file('game_stat.txt'), 'Counter-Strike')) print(reports.sort_abc(open_file('game_stat.txt'))) print(reports.get_genres(open_file('game_stat.txt'))) print(reports.when_was_top_sold_fps(open_file('game_stat.txt')))
def main(): try: with open(sys.argv[2], "w") as file: answer = reports.count_games(sys.argv[1]) write_answer_to_file(answer, file) answer = reports.decide(sys.argv[1], sys.argv[3]) write_answer_to_file(answer, file) answer = reports.get_latest(sys.argv[1]) write_answer_to_file(answer, file) answer = reports.count_by_genre(sys.argv[1], sys.argv[4]) write_answer_to_file(answer, file) answer = reports.get_line_number_by_title(sys.argv[1], sys.argv[5]) write_answer_to_file(answer, file) answer = reports.sort_abc(sys.argv[1]) write_answer_to_file(answer, file) answer = reports.get_genres(sys.argv[1]) write_answer_to_file(answer, file) answer = reports.when_was_top_sold_fps(sys.argv[1]) write_answer_to_file(answer, file) except IOError as e: print("[ERROR]: CANNOT WRITE INTO FILE " + str(e) + " !!!")
def file_export(file_name, year, title, genre): with open('export.txt', 'w') as f: f.write("1. How many games are in the file?\n") f.write(str(reports.count_games(file_name)) + "\n") f.write("2. Is there a game from a given year?\n") f.write(str(reports.decide(file_name, year)) + "\n") f.write("3. Which was the latest game?\n") f.write(str(reports.get_latest(file_name)) + "\n") f.write("4. How many games do we have by genre?\n") f.write(str(reports.count_by_genre(file_name, genre)) + "\n") f.write("5. What is the line number of the given game (by title)?\n") f.write(str(reports.get_line_number_by_title(file_name, title)) + "\n") f.write("------------------------------------\n" + "Extra\n") f.write("1. What is the alphabetical ordered list of the titles?\n") f.write(str(reports.sort_abc(file_name)) + '\n') f.write("2. What are the genres?\n") f.write(str(reports.get_genres(file_name)) + '\n') f.write( "3. What is the release date of the top sold 'First-person shooter' game?\n" ) f.write(str(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 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()