-
Notifications
You must be signed in to change notification settings - Fork 1
/
pizza.py
52 lines (36 loc) · 1.15 KB
/
pizza.py
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
import sys
from tabulate import tabulate
# I really just brute forced this tbh
def main():
if check_for_file():
get_menu()
def check_for_file() -> bool:
if len(sys.argv) < 2:
sys.exit("Too few command-line arguments")
elif len(sys.argv) > 2:
sys.exit("Too many command-line arguments")
if not sys.argv[1].endswith(".csv"):
sys.exit("Not a CSV File")
return True
def get_menu():
try:
with open(sys.argv[1]) as menu:
headers = []
table = []
for items in menu:
row = []
pizza, small, large = map(str, items.split(","))
if not headers:
headers.append(pizza)
headers.append(small)
headers.append(large.strip())
continue
row.append(pizza)
row.append(small)
row.append(large)
table.append(row)
print(tabulate(table, headers, tablefmt="grid"))
except FileNotFoundError:
sys.exit("CSV File not found")
if __name__ == "__main__":
main()