def remove_class(active_user): classes_to_remove = [] users_object_path = root / "user_objects" / active_user schedule = open(users_object_path, "rb") users_schedule = pickle.load(schedule) while True: class_to_remove = input( "Please enter the class you wish to remove in the same format you entered it " "\"[class, length day]\" ex: W60 1 3. Or type \"done\": \n") if class_to_remove.lower() == "done": break try: class_list = class_to_remove.split() if len(class_list) == 3: classes_to_remove.append( Session(class_list[0], class_list[1], class_list[2])) logger.debug("You have entered the following classes:", end=" ") for session in classes_to_remove: logger.debug(session.code, "day = " + session.day_taught, end=" ") logger.debug("\n") logger.info(active_user + "removed the class" + class_to_remove + " from their schedule.") else: logger.debug( "Sorry it seems the data you entered doesnt match the required format. Please try again" ) logger.info( active_user + "attempted to removed the class via incorrect input " + class_to_remove + " from their schedule.") except: logger.debug( "Sorry it seems the data you entered doesnt match the required format. Please try again" ) logger.info(active_user + "attempted to removed the class via incorrect input" + class_to_remove + " from their schedule.") for day in users_schedule.week: for user_session in day.sessions: for delete_session in classes_to_remove: if user_session.code == delete_session.code and user_session.length == delete_session.length \ and user_session.day_taught == delete_session.day_taught: day.sessions.remove(user_session) schedule = open(users_object_path, "wb") pickle.dump(users_schedule, schedule) schedule.close()
def createSession(user): """Create a session object for the imported user. Returns the session ID of the created session. ACTUAL SESSION MANAGEMENT IS NOT THE RESPONSIBILITY OF THIS METHOD.""" # Generate a random session ID randomID = get_random_string(8) while randomID in sessions: randomID = get_random_string(8) print(sessions) print( f"Creating new session with ID {randomID} and user account Num {user.accountNum}" ) # Create the new session and add it to the session dict newSession = Session(randomID, user.accountNum) sessions[randomID] = newSession return newSession
from objects import Session, Race session = Session() for race in session.query(Race): entry_result = repr(race.entries[0].result) marks = entry_result[1:-1].split(' ') race_result = repr(race.result) marks2 = race_result[1:-1].split(' ') if len(marks) != len(marks2): print(race.result) print(entry_result)
def create_schedule(active_user, make_or_write): sessions = [] users_object_path = root / "user_objects" / active_user logger.debug( "\nPlease input your class info in EXACTLY the same format that will be described below: \n " "[class (W55) length(in hours) day (as a num)]. \n" "Days taught are entered as a number between 1-5 [1 = Monday 5 = Friday] \n" "Use the following example to format your input: \"W60 1 3\".\n" "The above means class W60, taught for one hour, on Wednesday \n" "Do not include " " or a space before W in your input. \n") if make_or_write.lower() == "set": while True: session_info = input( "Please input class information or type \"done\" if you are finished: \n" ) if session_info.lower() == "done": break else: try: session_list = session_info.split() if len(session_list) == 3: sessions.append( Session(session_list[0], session_list[1], session_list[2])) logger.debug("You have entered the following classes:", end=" ") for session in sessions: logger.debug(session.code, "day = ", session.day_taught, end=" ") logger.debug("\n") logger.info(active_user + " added the class", session_info, "to there schedule.") else: logger.debug( "Sorry it seems the data you entered doesnt the required format. Please try again" ) logger.info(active_user + "attempted to add the incorrect format: " + session_info + " to their schedule.") except: logger.debug( "Sorry it seems the data you entered doesnt the required format. Please try again" ) logger.info(active_user + "attempted to add the incorrect format:" + session_info + "" " to their schedule.") monday_sessions = [] tuesday_sessions = [] wednesday_sessions = [] thursday_sessions = [] friday_sessions = [] for session in sessions: if session.day_taught == "1": monday_sessions.append(session) elif session.day_taught == "2": tuesday_sessions.append(session) elif session.day_taught == "3": wednesday_sessions.append(session) elif session.day_taught == "4": thursday_sessions.append(session) elif session.day_taught == "5": friday_sessions.append(session) week = [] monday = Day("Monday", monday_sessions) week.append(monday) tuesday = Day("Tuesday", tuesday_sessions) week.append(tuesday) wednesday = Day("Wednesday", wednesday_sessions) week.append(wednesday) thursday = Day("Thursday", thursday_sessions) week.append(thursday) friday = Day("Friday", friday_sessions) week.append(friday) users_schedule = User(active_user, week) schedule = open(users_object_path, "wb") pickle.dump(users_schedule, schedule) schedule.close() logger.debug( "\nYour schedule has been successfully created, the program will now return you " "to the previous menu.. \n \n") logger.info(active_user + "has successfully set up their schedule.")