def printing_report():
    print(reports.count_games("game_stat.txt"))
    print(reports.decide("game_stat.txt", "1998"))
    print(reports.get_latest("game_stat.txt"))
    print(reports.count_by_genre("game_stat.txt", "RPG"))
    print(reports.get_line_number_by_title("game_stat.tx",
                                           "World of Warcraft"))
Ejemplo n.º 2
0
def pprinter(file_name):
    pp = pprint.PrettyPrinter(indent=1, width=80, depth=None, stream=None)
    pp.pprint(reports.count_games('game_stat.txt'))
    pp.pprint(reports.decide('game_stat.txt', 2000))
    pp.pprint(reports.get_latest('game_stat.txt'))
    pp.pprint(reports.count_by_genre('game_stat.txt', 'RPG'))
    pp.pprint(reports.get_line_number_by_title('game_stat.txt', 'Minecraft'))
Ejemplo n.º 3
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")
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.º 5
0
    def test_2_decide(self):
        correct = True

        game_found = reports.decide(self.input_file, 2000)
        self.assertTrue(game_found)
        if not game_found:
            correct = False

        game_not_found = reports.decide(self.input_file, 2016)
        self.assertFalse(game_not_found)
        if game_not_found:
            correct = False

        if correct:
            self.points += 2
            print("Function 'decide' is passed. 2 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.º 7
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 test_2_decide(self):
        correct = True

        game_found = reports.decide(self.input_file, 2000)
        self.assertTrue(game_found)
        if not game_found:
            correct = False

        game_not_found = reports.decide(self.input_file, 2016)
        self.assertFalse(game_not_found)
        if game_not_found:
            correct = False

        if correct:
            self.points += 2
            print("Function 'decide' is passed. 2 points.")
Ejemplo n.º 9
0
def year_input(data_file):
    try:
        given_year = input(
            "Give me a year and I'll check if it is in the data file: ")
        chosen_year = str(reports.decide(data_file, int(given_year)))
    except ValueError:
        chosen_year = 'The given year was not a number!'
    return chosen_year
def decide_print(file_name):
    year = int(input("What year you are looking for? "))
    is_year_in_file = reports.decide(file_name, year)
    print('')  #blank line
    if is_year_in_file == True:
        print(f"Game from Year {year} is in file")
    else:
        print(f"Game from Year {year} isn't in file")
Ejemplo n.º 11
0
def print_game_given_year():
    boolean = reports.decide(file_name='game_stat.txt', year='2000')
    if boolean == 1:
        print('True')
    elif boolean == 2:
        print('False')
    else:
        pass
Ejemplo n.º 12
0
def printing_decide(file_name, year):
    """prints answer for question: is there a game from a given year?"""
    result = reports.decide(file_name, year)
    if result:
        print ("There is a game from", year, "year.")
    else:
        print ("There is not a game from", year, "year.")
    print()
def export(answer):
    filename = open("export.txt", "w")
    filename.write(str(reports.count_games(answer)) + "\n")
    filename.write(str(reports.decide(answer, 1998)) + "\n")
    filename.write(str(reports.get_latest(answer)) + "\n")
    filename.write(str(reports.count_by_genre(answer, "RPG")) + "\n")
    filename.write(
        str(reports.get_line_number_by_title(answer, "StarCraft")) + "\n")
Ejemplo n.º 14
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))
def export_answers(file_name='new_file.txt'):
    with open(file_name, "w") as txt:
        lines_of_text = [str(reports.count_games('game_stat.txt')), \
                         str(reports.decide('game_stat.txt', '2000')),\
                         reports.get_latest('game_stat.txt'), \
                         str(reports.count_by_genre('game_stat.txt', 'RPG')), \
                         str(reports.get_line_number_by_title('game_stat.txt', 'Doom 3'))]
        for item in lines_of_text:
            txt.write('%s\n' % item)
Ejemplo n.º 16
0
def export_decide(prompt):
    with open("export.txt", "a") as file_handler:
        year = input_tester(prompt)
        if decide("game_stat.txt", year):
            file_handler.write("There is a game in the file published in " +
                               str(year) + ".\n\n")
        else:
            file_handler.write("There is no game in the file published in " +
                               str(year) + ".\n\n")
Ejemplo n.º 17
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.º 18
0
def export_game_given_year():
    f = open("file.txt", "a")
    boolean = reports.decide(file_name='game_stat.txt', year='2000')
    if boolean == 1:
        print('True', file=f)
    elif boolean == 2:
        print('False', file=f)
    else:
        pass
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.º 20
0
def print_decide(file_name="game_stat.txt"):
    year = int(input("Enter a year to see if there are any games from then: "))
    if reports.decide(file_name, year):
        ans = "The file contains at least one game released in {}.".format(
            year)
    else:
        ans = "The file does not contain any games released in {}.".format(
            year)
    print(ans)
    return ans
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")
Ejemplo n.º 22
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.º 24
0
def execute_function(number, datafile):
    if number == COUNT_GAMES_NUMER:
        return reports.count_games(datafile)

    if number == DECIDE_NUMBER:
        return reports.decide(datafile, ask_for_a_year()) 

    if number == GET_LATEST_NUMBER:
        return reports.get_latest(datafile) 
    
    if number == COUNT_BY_GENRE_NUMBER:
        return reports.count_by_genre(datafile, ask_for_genre()) 
Ejemplo n.º 25
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.º 26
0
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
Ejemplo n.º 27
0
def display_decide():
    """Display if there is game from a given year."""
    year = int(input("Enter the searched year: "))
    value = reports.decide(filename, year)
    if value is True:
        print(
            "We have a game from {} year in {}\n" .format(
                str(year), filename))
    else:
        print(
            "Sorry, we don't have game from {} year in {}\n".format(
                str(year), filename))
def export_file(file_name):
    file = open(file_name, "w", newline='')
    writer = csv.writer(file, quoting=csv.QUOTE_MINIMAL)
    data = [
        reports.count_games("game_stat.txt"),
        reports.decide("game_stat.txt", 2000),
        reports.get_latest("game_stat.txt"),
        reports.count_by_genre("game_stat.txt", "RPG"),
        reports.get_line_number_by_title("game_stat.txt", "Terraria")
    ]
    for answer in data:
        writer.writerow([answer])
    file.close()
Ejemplo n.º 29
0
def export(file_name):
    with open(file_name, "w") as f:
        f.write(str(reports.count_games("game_stat.txt")))
        f.write("\n")
        f.write(str(reports.decide("game_stat.txt", "1998")))
        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", "RPG")))
        f.write("\n")
        f.write(
            str(
                reports.get_line_number_by_title("game_stat.txt",
                                                 "World of Warcraft")))
def main():
    output = open('output.txt', 'w')
    output.write(str(reports.count_games('game_stat.txt')))
    output.write('\n')
    output.write(str(reports.decide('game_stat.txt', 2000)))
    output.write('\n')
    output.write(reports.get_latest('game_stat.txt'))
    output.write('\n')
    output.write(str(reports.count_by_genre('game_stat.txt', 'RPG')))
    output.write('\n')
    output.write(
        str(reports.get_line_number_by_title('game_stat.txt', 'Crysis')))

    return
Ejemplo n.º 31
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.º 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))
Ejemplo n.º 33
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()
 def test_2_decide(self):
     result = reports.decide(self.input_file, 2000)
     self.assertTrue(result)
     if result:
         self.points += 2
         print("Function 'decide' is passed. 2 points.")
    print ("5: Number of the given name")
    menu = input("Type in the number of the desired option from above, or anything else to quit:\n")
    try:
        menu = int(menu)
    except:
        print ("Quit!")
        break
    if menu > 5 or menu < 1:
        print ("Quit!")
        break
    if menu == 1:
        file.write("Number of games: " + str(reports.count_games(filename)) + "\n")
    elif menu == 2:
        year = input("Which year?: ")
        try:
            year = int(year)
        except:
            print ("Invalid argument given!")
            break
        file.write("Is there a game from " + str(year) + ": " + str(reports.decide(filename, year)) + "\n")
    elif menu == 3:
        file.write("Latest game: " + reports.get_latest(filename) + "\n")
    elif menu == 4:
        genre = input("Which genre?: ")
        file.write("Number of " + genre + " games: " + str(reports.count_by_genre(filename, genre)) + "\n")
    elif menu == 5:
        title = input("Which game?: ")
        file.write("Number of " + title + ": " + str(reports.get_line_number_by_title(filename, title)) + "\n")
    print ("Exported!\n")
file.close()