-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask_users_options.py
More file actions
90 lines (74 loc) · 2.7 KB
/
ask_users_options.py
File metadata and controls
90 lines (74 loc) · 2.7 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
84
85
86
87
88
89
90
import sys, os
import toml
sys.dont_write_bytecode = True
def clear_console():
if os.name == 'nt': # For Windows
os.system('cls')
else: # For macOS and Linux
os.system('clear')
def ask_users_options():
clear_console()
if not os.path.exists("imformation.toml"):
with open("imformation.toml", "w", encoding="utf-8") as f:
toml.dump({'ID_NUMBER': '身分證字號', 'BIRTH': 'YYYMMDD', 'NAME': '中文姓名', 'PHONE': '手機電話', 'EMAIL': '電子郵件'}, f)
print("請先至imformation.toml 填妥個人資料")
input("按Enter 結束...")
sys.exit()
data = toml.load("keywords.toml")
for index, (key, value) in enumerate(data.items()):
print(str(index+1) + " " + value["name"])
MVO_index = int(input("選擇監理所: ")) - 1
print("\n")
if not 0 <= MVO_index < len(data):
print("\n不合理的選擇")
input("按Enter 結束...")
sys.exit()
clear_console()
# Motor Vehicle Office
MVO = list(data.keys())[MVO_index]
# 打印監理所轄下的監理站
sub_keys = [sub_key for sub_key in data[MVO] if isinstance(data[MVO][sub_key], dict)]
for index, sub_key in enumerate(sub_keys):
sub_value = data[MVO][sub_key]
print(f"{index+1}. {sub_value['Station']}")
# Prompt user to choose from Station options
station_index = int(input("請選擇監理站: ")) - 1
print("\n")
if not 0 <= station_index < len(sub_keys):
print("\n不合理的選擇")
input("按Enter 結束...")
sys.exit()
clear_console()
selected_station = data[MVO][sub_keys[station_index]]
print("是否重考:")
print("1. 初次考試")
print("2. 重考")
option = input("請選擇: ")
print("\n")
Retake, keyword = None, None
match option:
case "1":
Retake = False
keyword = selected_station["First"]
case "2":
Retake = True
keyword = selected_station["Retake"]
case _:
print("不合理的選擇")
input("按Enter 結束...")
sys.exit()
clear_console()
imformation = toml.load("imformation.toml")
print("資料如下:")
print(data[MVO]["name"])
print(selected_station["Station"])
print(f"重考:{Retake}")
for key, value in imformation.items():
print(f"{key}:{value}")
quit = input("\n確認後請按Enter繼續或打q退出: ")
if quit.lower() == "q":
sys.exit()
clear_console()
return {"MVO" : MVO, "Station" : selected_station["Station"], "Retake" : Retake, "Keywords" : keyword}
if __name__ == "__main__":
print(ask_users_options())