Skip to content

Commit

Permalink
feat: add main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Thungghuan committed Oct 3, 2022
1 parent bf1a420 commit 0faf694
Showing 1 changed file with 85 additions and 15 deletions.
100 changes: 85 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@
from bus import Bus


def clear():
print("\033[H\033[J", end="")


def reset_console():
clear()
print("gzic_bus / gzic校巴预约")


def load_token():
token = ""
print("读取token文件中...")

if path.exists("token"):
with open("token") as f:
token = f.read().strip()

if check_token_expired(token):
print("token过期")
login()
else:
print("token读取成功")
else:
token = login()

return token


def login():
print("请先使用统一认证账号登陆获取token")
username = questionary.text("学号:").ask()
Expand All @@ -20,27 +48,33 @@ def login():
with open("token", "w+") as f:
f.write(token)

return token

def main():
print("gzic_bus / gzic校巴预约")

token = ""
print("读取token文件中...")
def check_reserve(bus: Bus):
tickets = bus.list_reserve(status=1)["list"]
ticket_choices = []

if path.exists("token"):
with open("token") as f:
token = f.read().strip()
for idx, bus in enumerate(tickets):
ticket_choices.append(
{
"name": "{}. {} {}".format(idx + 1, bus["ruteName"], bus["startTime"]),
"value": idx,
}
)

if check_token_expired(token):
print("token过期")
login()
else:
print("token读取成功")
if len(ticket_choices) > 0:
choice = questionary.select(
"请选择班次:",
choices=ticket_choices,
).ask()

print(choice)
else:
login()
print("没有找到预约的校巴哦")

bus = Bus(token)

def reserve_bus(bus: Bus):
campus = ["广州国际校区", "大学城校区", "五山校区"]

start_campus = questionary.select("请选择起点", choices=campus).ask()
Expand Down Expand Up @@ -73,14 +107,50 @@ def main():
[
("disabled", "#858585 italic"),
]
)
),
).ask()

reset_console()
print(bus_list[bus_idx])

else:
print("{}已经没有校巴了".format(date))


def quit():
clear()
print("88")


def main():
reset_console()

token = load_token()
bus = Bus(token)

reset_console()

menu = ["查看已预约校巴", "预约校巴", "退出"]
menu_choices = []

function_list = [check_reserve, reserve_bus, quit]

for idx, choice in enumerate(menu):
menu_choices.append(
{
"name": "({}). {}".format(idx + 1, choice),
"value": idx,
}
)

choice = questionary.select(
"请选择功能:",
choices=menu_choices,
).ask()

print(menu[choice])
function_list[choice](bus)


if __name__ == "__main__":
main()

0 comments on commit 0faf694

Please sign in to comment.