Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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():
    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))
Ejemplo n.º 4
0
 def test_bonus_3_when_was_top_sold_fps(self):
     result = reports.when_was_top_sold_fps(self.input_file)
     self.assertEqual(result, 1999)
     if result == 1999:
         self.points += 1
         print(
             "Bonus function 'when_was_top_sold_fps' is passed. 1 points.")
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))
Ejemplo n.º 6
0
def printing_when_was_top_sold_fps(file_name):
    """prints year of the release top sold "First-person shooter game"""
    try:
        result = reports.when_was_top_sold_fps(file_name)
        print ("The year of release First-person shooter is: ", result)
    except ValueError:
        print ("There is no game with genre 'First-person shooter'")
    print()
Ejemplo n.º 7
0
def print_release_date(file_name):
    try:
        year_top_sold = reports.when_was_top_sold_fps(file_name)
    except ValueError:
        year_top_sold = "No FPS game in database"
    print(
        f"What is the release date of the top sold 'First-person shooter' game? {year_top_sold}"
    )
def print_year_of_top_sold_fps(file_name):
    try:
        year_of_top_sold_fps = reports.when_was_top_sold_fps(file_name)
    except ValueError:
        year_of_top_sold_fps = "No 'First-person shooter' game in the database!"
    print(
        f"The release year of the top sold 'First-person shooter' game: {year_of_top_sold_fps}"
    )
Ejemplo n.º 9
0
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))
Ejemplo n.º 10
0
def export_when_was_top_sold_fps():
    """Export to file: release date of the top sold "First-person shooter"."""
    genre = input("Please, give me a searched genre game: ")
    top_game = reports.when_was_top_sold_fps(filename, genre)
    message = "The top sold {} genre was released in: {}".format(
        genre, top_game)

    export_to_file(message)
    print("DATA TRANSFERRED TO A FILE: exported_answers.txt!\n")
Ejemplo n.º 11
0
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())
Ejemplo n.º 12
0
def writing_when_was_top_sold_fps(file_name):
    """writes down year of the release top sold "First-person shooter game"""
    with open("report_for_judy.txt", "a") as f:
        try:
            result = str(reports.when_was_top_sold_fps(file_name))
            f.write(result)
            f.write("\n")
        except ValueError:
            f.write("There is no game with genre 'First-person shooter'")
            f.write("\n")
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"))
Ejemplo n.º 15
0
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"
    ])
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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")
Ejemplo n.º 20
0
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")
Ejemplo n.º 21
0
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
Ejemplo n.º 23
0
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"))
Ejemplo n.º 24
0
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 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)))
Ejemplo n.º 28
0
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 main():
    input_file = 'game_stat.txt'
    export_file = open('reports.txt', 'w')

    export_file.write('How many games are in the file?\n')
    export_file.write(str(r.count_games(input_file)) + '\n\n')

    export_file.write('Is there a game from 2000?\n')
    export_file.write(str(r.decide(input_file, 2000)) + '\n\n')

    export_file.write('Which was the latest game?\n')
    export_file.write(str(r.get_latest(input_file)) + '\n\n')

    export_file.write(
        'How many games do we have by the First-person shooter genre?\n')
    export_file.write(
        str(r.count_by_genre(input_file, 'First-person shooter')) + '\n\n')

    export_file.write('What is the line number of Counter-Strike?\n')
    export_file.write(
        str(r.get_line_number_by_title(input_file, 'Counter-Strike')) + '\n\n')

    export_file.write('What is the alphabetical ordered list of the titles?\n')
    ordered_titles = r.sort_abc(input_file)
    for title in ordered_titles:
        export_file.write(title)
        export_file.write('\n')

    export_file.write('\nWhat are the genres?\n')
    genres = r.get_genres(input_file)
    for genre in genres:
        export_file.write(genre)
        export_file.write('\n')

    export_file.write(
        '\nWhat is the release date of the top sold "First-person shooter" game?\n'
    )
    export_file.write(str(r.when_was_top_sold_fps(input_file)))

    export_file.close()
Ejemplo n.º 30
0
def export_answers():
    import reports
    with open("export_answers.txt", "w") as f:
        f.write(str(reports.count_games("game_stat.txt")))
        f.write("\n")
        f.write(str(reports.decide("game_stat.txt", "1999")))
        f.write("\n")
        f.write(str(reports.get_latest("game_stat.txt")))
        f.write("\n")
        f.write(
            str(reports.count_by_genre("game_stat.txt", "Real-time strategy")))
        f.write("\n")
        f.write(
            str(
                reports.get_line_number_by_title(
                    "game_stat.txt", "Counter-Strike: Condition Zero")))
        f.write("\n")
        f.write(str(reports.sort_abc("game_stat.txt")))
        f.write("\n")
        f.write(str(reports.get_genres("game_stat.txt")))
        f.write("\n")
        f.write(str(reports.when_was_top_sold_fps("game_stat.txt")))
Ejemplo n.º 31
0
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()
Ejemplo n.º 32
0
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))
 def test_bonus_3_when_was_top_sold_fps(self):
     result = reports.when_was_top_sold_fps(self.input_file)
     self.assertEqual(result, 1999)
     if result == 1999:
         print("Bonus function 'when_was_top_sold_fps' is passed.")
 def test_bonus_3_when_was_top_sold_fps(self):
     result = reports.when_was_top_sold_fps(self.input_file)
     self.assertEqual(result, "Counter-Strike")
     if result == "Counter-Strike":
         self.points += 1
         print("Bonus function 'when_was_top_sold_fps' is passed. 1 points.")