예제 #1
0
def run():
    json_object = json.loads(
        Path('data/gamers.json').read_text(encoding='utf8'))
    print(f"Read information about {len(json_object['gamers'])} LAN gamers.")
    ans = input(
        """I'm ready to analyze that data, but first, what output format do you want?
    1. HTML (will open in browser)
    2. CSV (you may open in Excel e.g)
    3. Console (display it here)
Your choice: """)
    path = Path("../langames/data")
    if ans == "1":
        table_builder = HtmlTableBuilder()
        analyze(json_object, table_builder)
        html_content = table_builder.get_html()
        p = path / "output.html"
        p.write_text(html_content, encoding='utf8')
        print(f"Opening {p} in your default web browser...")
        webbrowser.open(str(p))
    elif ans == "2":
        table_builder = CsvTableBuilder()
        analyze(json_object, table_builder)
        csv_string = table_builder.get_csv_text()
        p = path / "output.csv"
        p.write_text(csv_string, encoding='utf8')
        print(f"The CSV file has been written to {p}.")
    elif ans == "3":
        table_builder = ConsoleTableBuilder(column_width=20)
        analyze(json_object, table_builder)
        text = table_builder.get_string_output()
        print(text)
    else:
        print("Not a valid option, quitting.")
        return
예제 #2
0
def test_simple_2x2_text_table():
    builder = ConsoleTableBuilder(column_width=10)
    builder.set_headers(['Anna', 'Kalle'])
    builder.add_row(['1', '2'])
    builder.add_row(['3', '4'])
    # TODO: Fill in expected string below!
    expected = ''
    actual = builder.get_string_output()
    assert expected == actual
def test_simple_2x2_text_table():
    builder = ConsoleTableBuilder(column_width=10)
    builder.set_headers(['Anna', 'Kalle'])
    builder.add_row(['1', '2'])
    builder.add_row(['3', '4'])
    expected = f'{"Anna":>10}{"Kalle":>10}\n' \
               f'{"1":>10}{"2":>10}\n' \
               f'{"3":>10}{"4":>10}\n'
    got = builder.get_string_output()
    assert expected == got
예제 #4
0
def test_simple_2x2_text_table():
    builder = ConsoleTableBuilder(column_width=10)
    builder.set_headers(['Anna', 'Kalle'])
    builder.add_row(['1', '2'])
    builder.add_row(['3', '4'])
    expected = '''      Anna     Kalle
         1         2
         3         4
'''
    got = builder.get_string_output()
    assert expected == got
예제 #5
0
def test_simple_2x2_text_table():
    builder = ConsoleTableBuilder(column_width=10)
    builder.set_headers(['Anna', 'Kalle'])
    builder.add_row(['1', '2'])
    builder.add_row(['3', '4'])

    #expected = "      Anna     Kalle\n         1         2\n         3         4\n"
    expected = "{name1:>10} {name2:>10} {val11:>9} {val12:>10} {val21:>9} {val22:>10}".format(
        name1="Anna",
        name2="Kalle\n",
        val11="1",
        val12="2" + '\n',
        val21="3",
        val22="4\n")
    got = builder.get_string_output()
    assert expected == got