Databases now contain all classes' data
This commit is contained in:
parent
b7611be5ee
commit
e8f51079d7
2
TODO.md
2
TODO.md
@ -3,7 +3,7 @@ To-Do List
|
||||
|
||||
## v0.2
|
||||
- [x] Error handling (when entering invalid data types)
|
||||
- [ ] Make database contain data for all classes
|
||||
- [x] Make database contain data for all classes
|
||||
- [ ] Flexible mandatory subjects
|
||||
|
||||
## v0.3
|
||||
|
@ -28,35 +28,37 @@ def connect_database(file):
|
||||
return conn
|
||||
|
||||
|
||||
def request_id(conn):
|
||||
def get_data(conn):
|
||||
"""
|
||||
Request student ID, validate, and return.
|
||||
Requests student ID and returns integer tuple (id, class) with valid
|
||||
student id and corresponding class no.
|
||||
:param conn: Connection object
|
||||
"""
|
||||
try:
|
||||
id = int(input("Please enter student ID: "))
|
||||
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT id FROM students")
|
||||
cur.execute("SELECT id, student_class FROM students")
|
||||
ids = cur.fetchall()
|
||||
|
||||
for x in ids:
|
||||
# ids are single value tuples
|
||||
# ids is list with single value tuples
|
||||
if id == x[0]:
|
||||
return id
|
||||
# return tuple x with valid id and corresponding class no.
|
||||
return x
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
print("Incorrect ID, try again.")
|
||||
request_id(conn)
|
||||
return get_data(conn)
|
||||
|
||||
|
||||
def select_final_time(conn, day, id):
|
||||
def select_final_time(conn, day, stud):
|
||||
"""
|
||||
Returns ending time of final lesson student must attend, or None.
|
||||
:param conn: Connection object
|
||||
:param day: current weekday, lowercase str
|
||||
:param id: ID of student, int
|
||||
:param stud: tuple with student ID no. and class no., int
|
||||
"""
|
||||
cur = conn.cursor()
|
||||
cur.execute("""
|
||||
@ -70,10 +72,12 @@ def select_final_time(conn, day, id):
|
||||
OR g6 = lesson_id
|
||||
OR lesson_id = 'gu'
|
||||
OR lesson_id = 'tok'
|
||||
WHERE id = ? AND day = ?
|
||||
WHERE id = ?
|
||||
AND day = ?
|
||||
AND lesson_class = ?
|
||||
ORDER BY end_time DESC
|
||||
LIMIT 1
|
||||
""", (id, day))
|
||||
""", (stud[0], day, stud[1]))
|
||||
finish = cur.fetchone()
|
||||
if str(type(finish)) == "<class 'tuple'>":
|
||||
return finish[0]
|
||||
@ -86,8 +90,8 @@ def parse_time_string(timestring):
|
||||
Parses given 24h time string of format "HH:MM" into struct_time.
|
||||
:param timestring: time string "HH:MM"
|
||||
"""
|
||||
timestruct = time.strptime(timestring, "%H:%M")
|
||||
return timestruct
|
||||
structtime = time.strptime(timestring, "%H:%M")
|
||||
return structtime
|
||||
|
||||
|
||||
def main():
|
||||
@ -97,7 +101,7 @@ def main():
|
||||
conn = connect_database("database.db")
|
||||
|
||||
while True:
|
||||
id = request_id(conn)
|
||||
id = get_data(conn)
|
||||
day = time.strftime("%A").lower()
|
||||
finish_time = select_final_time(conn, day, id)
|
||||
current_time = time.strftime("%H:%M")
|
||||
|
Reference in New Issue
Block a user