From be5ff7177c3769fb400f945c37831c14c0b36f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Wed, 26 Dec 2018 21:03:01 +0100 Subject: [PATCH] Handle ValueError. --- .gitignore | 1 + TODO.md | 2 +- ib-clearance.py | 33 ++++++++++++++++++--------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 8068375..dc3d2c0 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,4 @@ dmypy.json # database files (may contain sensitive student info) *.db +.vscode diff --git a/TODO.md b/TODO.md index 1ba19ec..0e407ad 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ To-Do List ========== ## v0.2 -- [ ] Error handling (when entering invalid data types) +- [x] Error handling (when entering invalid data types) - [ ] Make database contain data for all classes - [ ] Flexible mandatory subjects diff --git a/ib-clearance.py b/ib-clearance.py index b7e3382..3469c12 100755 --- a/ib-clearance.py +++ b/ib-clearance.py @@ -102,23 +102,26 @@ def main(): y = "y" while y == "y": - id = int(input("Please input the student ID number: ")) + try: + id = int(input("Please input the student ID number: ")) - if check_id(conn, id): - day = get_lower_weekday() - raw_time = select_final_time(conn, day, id) - # if raw_time is None, student has no lessons today - if raw_time != None: - final_time = parse_time_string(raw_time) - current_time = parse_time_string(time.strftime("%H:%M")) - if current_time > final_time: + if check_id(conn, id): + day = get_lower_weekday() + raw_time = select_final_time(conn, day, id) + # if raw_time is None, student has no lessons today + if raw_time != None: + final_time = parse_time_string(raw_time) + current_time = parse_time_string(time.strftime("%H:%M")) + if current_time > final_time: + print("Clear to leave.") + else: + print("Student does not have clearance.") + elif raw_time == None: print("Clear to leave.") - else: - print("Student does not have clearance.") - elif raw_time == None: - print("Clear to leave.") - else: - print("Student does not exist in the database. Please try again.") + else: + print("Student does not exist in the database. Please try again.") + except ValueError: + print("That was not an integer, please try again.") y = input("Press y key followed by enter to run again.")