def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) print("Representación de los slots:") color_print_slots(tracker) subject_acro = tracker.get_slot("subject_acronym").upper() chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] teachers_info = API_raco().get_subject_teachers(acronym=subject_acro, language=user_lang) teachers_info = Subject_teachers(subject_acro, teachers_info, user_lang) if teachers_info.amount <= 4: for response in teachers_info.get_offices(): dispatcher.utter_message("{}".format(response)) else: answers = { 'ca': "Aquests són els professors de {}. Qui t'interessa?!\n", 'es': 'Éstos son los profesores de {}. ¿Quién te interesa?\n', 'en': "These are {}'s teachers. Who are you interested in?\n" } answer = answers[user_lang].format(subject_acro) for teacher in teachers_info.get_names(): answer = answer + teacher + '\n' dispatcher.utter_message("{}".format(answer)) return [SlotSet("matches", True)] return [SlotSet("matches", False)]
def __init__(self, mh, delay, thread_logging = True): self.api = API_raco() self.message_handler = mh self.thread_logging = thread_logging self.chats = self.message_handler.chats self.delay = delay self.thread = None self.polling = True self.last_check = datetime.datetime.now() self.retrieve_timestamp() log("Marca temporal cargada: {}".format(self.last_check))
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) print("Representación de los slots:") color_print_slots(tracker) subject_acro = tracker.get_slot("subject_acronym").upper() chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] access_token = Chats().get_chat_lite(chat_id)['access_token'] response = API_raco().get_schedule(access_token, user_lang, subject_acro) for data in response: lecture = Lecture(data, user_lang) dispatcher.utter_message("{}".format(lecture)) return []
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) print("Representación de los slots:") color_print_slots(tracker) chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] access_token = Chats().get_chat_lite(chat_id)['access_token'] schedule = API_raco().get_schedule(access_token=access_token, language=user_lang) schedule = Schedule(schedule, user_lang) answer = schedule.get_response() if isinstance(answer, list): dispatcher.utter_message("{}".format(answer[0])) else: dispatcher.utter_message("{}".format(answer)) return []
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) subject_acro = tracker.get_slot("subject_acronym").upper() chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] access_token = Chats().get_chat_lite(chat_id)['access_token'] if not API_raco().user_enrolled_subject(subject_acro, access_token, user_lang): response = str(Not_understood(user_lang, 'not_enrolled')) if '{}' in response: dispatcher.utter_message(response.format(subject_acro)) else: dispatcher.utter_message(response) print(colored("El usuario NO está matriculado", 'red')) return [SlotSet("subject_enrollment", False)] else: print(colored("El usuario está matriculado", 'green')) return [SlotSet("subject_enrollment", True)]
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) subject_acro = tracker.get_slot("subject_acronym") chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] if subject_acro: subject_acro = subject_acro.upper() if not API_raco().subject_exists(subject_acro): dispatcher.utter_message( str(Not_understood(user_lang, 'wrong_subject'))) else: print(colored("Asignatura existe", 'green')) return [SlotSet("subject_existance", True)] else: dispatcher.utter_message("{}".format( Not_understood(user_lang, 'not_understand'))) print(colored("Asignatura NO existe", 'red')) return [SlotSet("subject_existance", False)]
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) print("Representación de los slots:") color_print_slots(tracker) subject_acro = tracker.get_slot("subject_acronym").upper() chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] teachers_info = API_raco().get_subject_teachers(acronym=subject_acro, language=user_lang) teachers_info = Subject_teachers(subject_acro, teachers_info, user_lang) answers = { 'ca': "Aquests són els professors de {}:\n", 'es': 'Éstos son los profesores de {}:\n', 'en': "These are {}'s teachers:\n" } answer = answers[user_lang].format(subject_acro) for teacher in teachers_info.get_names(): answer = answer + teacher + '\n' dispatcher.utter_message("{}".format(answer)) return []
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) print("Representación de los slots:") color_print_slots(tracker) chat_id = tracker.sender_id subject_acro = tracker.get_slot("subject_acronym") user_lang = Chats().get_chat_lite(chat_id)['language'] access_token = Chats().get_chat_lite(chat_id)['access_token'] if subject_acro: acro_filter = subject_acro else: acro_filter = None pracs = list(API_raco().get_practiques(access_token=access_token, language=user_lang)) p_e = Practical_schedule(pracs, user_lang) pracs = list(p_e.get_closest_pracs(range=62, acro_filter=acro_filter)) if pracs: for prac in pracs: dispatcher.utter_message("{}".format(prac)) tracker._reset_slots() return [] dispatcher.utter_message("{}".format( Not_understood(user_lang, 'not_pracs'))) return []
def run(self, dispatcher, tracker, domain): print("\nEjecutando acción:\t{}".format( colored(self.name(), 'yellow', attrs=['bold']))) print("Representación de los slots:") color_print_slots(tracker) subject_acro = tracker.get_slot("subject_acronym").upper() group = tracker.get_slot("group") chat_id = tracker.sender_id user_lang = Chats().get_chat_lite(chat_id)['language'] response = list(API_raco().get_free_spots(subject_acro, user_lang)) if not response: dispatcher.utter_message("{}".format( Not_understood( user_lang, 'not_enrollment_possible')).format(subject_acro)) return [] s_s = Subject_spots(response, user_lang) if group: dispatcher.utter_message("{}".format(s_s.get_group_spots(group))) else: for group in s_s.group_info.keys(): dispatcher.utter_message("{}".format( s_s.get_group_spots(group))) return []
from Fibot.chats import Chats from Fibot.api.api_raco import API_raco from Fibot.Data.data_types.exam import Exam_schedule from Fibot.Data.data_types.practical_work import Practical_schedule from pprint import pprint c = Chats() c.load() a = API_raco() a_t = c.get_chat('349611162')['access_token'] user_lang = c.get_chat('349611162')['language'] exams = list(a.get_exams_user(a_t)) e_e = Exam_schedule(exams, user_lang) pprint(list(e_e.get_closest_exams(range=50))) pracs = list(a.get_practiques(a_t)) p_e = Practical_schedule(pracs, user_lang) pprint(list(p_e.get_closest_pracs(range=50)))