-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (61 loc) · 2.24 KB
/
main.py
File metadata and controls
83 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from enum import Enum
import csv_table.csv_table as cvt
import table_renderer.table_renderer as tr
import sys
class UserInput(Enum):
FIRST_PAGE = 0
PREVIOUS_PAGE = 1
NEXT_PAGE = 2
LAST_PATE = 3
EXIT = 4
NOT_PARSED = 5
def render_menue():
print("F)irst page, P)revious page, N)ext page, L)ast page, E)xit")
def parse_user_input(user_input: str) -> UserInput:
if user_input in ["F", "f", "First page", "first page"]:
return UserInput.FIRST_PAGE
if user_input in ["P", "p", "Previous page", "previous page"]:
return UserInput.PREVIOUS_PAGE
if user_input in ["N", "n", "Next page", "next page"]:
return UserInput.NEXT_PAGE
if user_input in ["E", "e", "Exit", "exit"]:
return UserInput.EXIT
else:
return UserInput.NOT_PARSED
def render_page_count(table):
current_page_number = table.get_current_page_index() + 1
last_page_number = table.get_last_page_index() + 1
print("Page {current} of {max}".format(current=current_page_number, max=last_page_number))
pass
def main(path: str, page_length: int):
table = cvt.load_csv(path)
table.set_page_length(page_length)
should_exit = False
while not should_exit:
render_table(table)
render_page_count(table)
use_input = parse_user_input(
input("F)irst page, P)revious page, N)ext page, L)ast page, E)xit \n"))
if use_input == UserInput.FIRST_PAGE:
table.set_page_to_first()
if use_input == UserInput.LAST_PATE:
table.set_page_to_last()
if use_input == UserInput.NEXT_PAGE:
table.increment_page()
if use_input == UserInput.PREVIOUS_PAGE:
table.decrement_page()
should_exit = use_input == UserInput.EXIT
def render_table(table):
output = tr.create_table_markup_str(table.caption, table.get_body())
print(output)
def read_data(path: str) -> str:
f = open(path)
lines = f.readlines()
return "".join(lines)
def parse_program_input(argv: list[str]) -> (str, int):
path = argv[0]
size = int(argv[1]) if (len(argv)) > 1 else 3
return path, size
if __name__ == '__main__':
table_path, page_size = parse_program_input(sys.argv[1:])
main(table_path, page_size)