def get_professors_that_take_a_course(course): print(course) if course is None: return "Mi dispiace, non so rispondere alla tua domanda" course = str(course).lower() session = start_session() queryset = session.query(Course).filter(or_(Course.alias == course)) courses_list = queryset2list(queryset) session.close() if courses_list.__len__() == 0: return "Nessun professore tiene il corso di " + course.title() elif courses_list.__len__() == 1: professor = get_professor(courses_list[0].professor) if professor.gender == 'male': title = 'dal professor ' else: title = 'dalla professoressa ' return "Il corso di " + str( courses_list[0].course_name).title() + " è tenuto " + title + str( professor.full_name).title() else: speech_text = "Il corso di " + str( courses_list[0].course_name).title() + " è tenuto dai professori " for course in courses_list: if (courses_list.index(course) + 1) == courses_list.__len__(): speech_text = speech_text + " e " + str( course.professor).title() else: speech_text = speech_text + str( course.professor).title() + ", " return speech_text
def get_professor_courses(professor): if professor is None: return "Mi dispiace, non so rispondere alla tua domanda" professor_result = get_professor(professor) if professor_result is not None: if professor_result.gender == 'male': title = 'il professor ' else: title = 'la professoressa ' full_name_professor = professor_result.full_name session = start_session() queryset = session.query(Course).filter( Course.professor == full_name_professor) courses_list = queryset2list(queryset) session.close() if courses_list.__len__() == 0: return "Attualmente " + title + full_name_professor.title( ) + " non tiene nessun corso" elif courses_list.__len__() == 1: return "Attualmente " + title + full_name_professor.title( ) + " tiene il corso di " + str( courses_list[0].course_name).title() else: speech_text = "Attualmente " + title + full_name_professor.title( ) + " tiene i corsi di " for course in courses_list: if (courses_list.index(course) + 1) == courses_list.__len__(): speech_text = speech_text + " e di " + str( course.course_name).title() else: speech_text = speech_text + str( course.course_name).title() + ", " return speech_text else: return "Mi dispiace, non so rispondere alla tua domanda"
def check_active_user(): session = start_session() queryset = session.query(User).filter(User.active == True) session.close() if not queryset2list(queryset).__len__() > 0: return None, None, False user = queryset2list(queryset)[0] return user.name, user.year, True
def get_schedule_from_time(day, time, year): day = get_day_number(day) session = start_session() queryset = session.query(Schedule).filter(and_(Schedule.time == time, Schedule.day == day, Schedule.year == year)) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset)[0] else: return None
def get_room_and_time_schedule(day, course, year): course = str(course).lower() session = start_session() queryset = session.query(Schedule).filter(and_(Schedule.day == get_day_number(day), Schedule.year == year, or_(Schedule.course == course, Schedule.alias == course))) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset)[0] else: return None
def get_course_schedule(course, year): course = str(course).lower() session = start_session() queryset = session.query(Schedule).filter(and_(Schedule.year == year, or_(Schedule.course == course, Schedule.alias == course))) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset) else: return None
def get_exams_schedule(exam): exam = str(exam).lower() date = datetime.datetime.now().date().isoformat() session = start_session() queryset = session.query(Exam).filter(and_(Exam.date>date, or_(Exam.short == exam, Exam.course_name == exam ))) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset) else: return None
def get_menu(day): if day is None: day = 'oggi' day = get_day_number(day) session = start_session() queryset = session.query(Menu).filter(Menu.day == day) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset)[0] else: return None
def get_day_schedule(day,year): day = get_day_number(day) if day < 5: session = start_session() queryset = session.query(Schedule).filter(and_(Schedule.day == day, Schedule.year == year)) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset) else: return None return None
def get_professor(professor): professor = str(professor).lower() session = start_session() queryset = session.query(Professor).filter( or_(Professor.surname == professor, Professor.full_name == professor, Professor.full_name == reverse_words(professor))) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset)[0] else: return None
def get_next_chance(exam): exam = str(exam).lower() date = datetime.datetime.now().date().isoformat() session = start_session() queryset = session.query(func.min(Exam.date)).filter(and_(Exam.date>date, or_(Exam.short == exam, Exam.course_name == exam ))) date = queryset2list(queryset)[0][0] queryset = session.query(Exam).filter(Exam.date == date) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset)[0] else: return None
def change_user_db(name, flag=True): name = str(name).lower() session = start_session() session.query(User).filter(User.active == True).update({"active": False}) session.commit() queryset = session.query(User).filter(User.name == name) if not queryset2list(queryset).__len__() > 0: session.close() return False if flag: session.query(User).filter(User.name == name).update({'active': True}) session.commit() session.close() return True
def add_user_db(name, year): if name is None or year is None: return False name = str(name).lower() year = str(year).lower() if year == 'primo': year = 1 elif year == 'secondo': year = 2 else: return False session = start_session() queryset = session.query(User).filter(User.name == name) session.close() if queryset2list(queryset).__len__() > 0: session.close() return False change_user_db(name, False) user = User(name=name, year=year, active=True) session = start_session() session.add(user) session.commit() session.close() return True
def get_calendar_activity(day, month): date = datetime.datetime.now().date().isoformat() year,current_month,_ = date.split("-") current_month_number = int(current_month) month_number = int(get_month_number(month)) if current_month_number > month_number: year = str(int(year)+1) if int(day) < 10: day = f'0{day}' date = f'{year}-{get_month_number(month)}-{day}' session = start_session() queryset = session.query(Calendar.activity).filter(and_(Calendar.start <= date, date <= Calendar.end)) session.close() if queryset2list(queryset).__len__() > 0: return queryset2list(queryset)[0][0] else: return None
def remove_user(name): if name is None: return False name = str(name).lower() session = start_session() queryset = session.query(User).filter(User.name == name) if not queryset2list(queryset).__len__() > 0: session.close() return False user = queryset2list(queryset)[0] session.delete(user) session.commit() queryset = session.query(User).filter(User.name == name) session.close() if queryset2list(queryset).__len__() > 0: return False return True
def change_year(name, year): if name is None and year is None: return False name = str(name).lower() year = str(year).lower() if year == 'primo': year = 1 elif year == 'secondo': year = 2 else: return False session = start_session() session.query(User).filter(User.name == name).update({"year": year}) session.commit() queryset = session.query(User.year).filter(User.name == name) session.close() if int(queryset2list(queryset)[0][0]) == year: return True return False