def announcement_list(url, data, tracker): try: text = "" res = api_reader(url, httpmethod="post", data=data, tracker=tracker) logger.success(f"api call on url {url} done sucessfully") if not res["content"]: return res["content"] for i, p in enumerate(res["content"]): title = str(p["title"]) message = str(p["message"]) epochtime = p["publishedDate"] published_date = time.localtime(epochtime / 1000) published_date = datetime.fromtimestamp(mktime(published_date)) published_date = published_date + timedelta(hours=5, minutes=45) published_date = published_date.strftime("%m/%d/%Y, %H:%M") text = text + announcement_template.format( title=title, message=message, published_date=published_date ) if i == 4: break return "**Your recent announcements are:** \n\n" + text except Exception as e: logger.exception(f"Parsing of API resuts failed") return None
def teacher_info(url, params, attribute, tracker): if attribute is None: return None try: res = api_reader(url, params=params, tracker=tracker) logger.success(f"api call on url {url} done sucessfully") for p in res: return p.get(attribute) except Exception as e: logger.exception(f"Api call on url {url} Failed") return None
def object_list(object_type, tracker): try: url = "api/v2/enrolledCourses" results = api_reader(url, tracker=tracker) logger.info(f"object list results is {results}") object_list = [] for p in results: if object_type == "courseBy": object_list.append(p[object_type][0]) else: object_list.append(p[object_type]) return object_list except Exception as e: logger.exception(f"Parsing of API resuts failed") return None
def assignment_list(context, url, params, tracker): text = "" try: res = api_reader(url, params, tracker=tracker) if not res: return res logger.info(f"The assignments list are:\n{res}") for i, p in enumerate(res["content"]): title = p["assignment"]["assignmentTitle"] logger.info(f"data is {p['assignment']}") epochtime = p["assignment"]["deadLine"] try: grade = p["assignment"]["totalGrade"] except: grade = "NOT Available" deadline = time.localtime(epochtime / 1000) deadline = datetime.fromtimestamp(mktime(deadline)) deadline = deadline + timedelta(hours=5, minutes=45) deadline = deadline.strftime("%m/%d/%Y, %H:%M") text = text + assignement_template.format( title=title, deadline=deadline, grade=grade ) if i == 4: break if context == "help_upcoming_assignments": if text: return "**The upcoming assignments are** \n\n" + text return "Currently, you have no any upcoming assignments.😀" elif context == "help_late_assignments": if text: return "**The late assignments are** \n\n" + text return "Congrats!!! you have completed all the assignments till now.😀" except Exception as e: logger.exception(f"Parsing of API resuts failed") return None
def grade_list(url, tracker): text = "" try: res = api_reader(url, tracker=tracker) logger.success(f"api call on url {url} done sucessfully") if not res: return res for p in res[0]["academicCourses"]: course = str(p["courseName"]) gpa = str(p["courseGpa"]) text = text + grade_template.format(course=course, gpa=gpa) return "**These are your grades:** \n\n" + text except Exception as e: logger.exception(f"Parsing of API resuts failed") return None
async def run( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: DomainDict, ) -> List[EventType]: last_message = tracker.latest_message.get("text") school_id = extract_schoolid_from_tracker(tracker) buttonid = search_query_fallback(last_message, school_id) if isinstance(buttonid, str): return [ SlotSet("buttonid", buttonid), FollowupAction("action_queryredisid"), ] elif isinstance(buttonid, zip): buttons = [] for objectid, label in buttonid: payload = { "buttonid": objectid, "new_action": "action_queryredisid", } payload = json.dumps(payload) buttons.append( {"title": label, "payload": f"/router{payload}",} ) message_title = "Do you mean any of these" dispatcher.utter_message(text=message_title, buttons=buttons) return [] else: dispatcher.utter_message( "Sorry something is wrong.Please try again later." ) logger.exception( "ES server is not returning any results.please once look into corresponding index" ) return [ SlotSet("new_action", "action_help_menu"), SlotSet("context", "help"), FollowupAction("action_router"), ]
def quiz_list(url, params, tracker, context): text = "" try: res = api_reader(url, params, tracker=tracker) logger.success(f"api call on url {url} done sucessfully") if not res["content"]: return res["content"] for i, p in enumerate(res["content"]): title = str(p["quizTitle"]) description = str(p["quizDescription"]) score = str(p["fullScore"]) if p["obtainedScore"] and str(p["obtainedScore"]) != "null": obtained_score = str(format(p["obtainedScore"], ".2f")) else: obtained_score = "Not Available" text = text + quiz_template.format( obtained_score=obtained_score, title=title, description=description, score=score, ) if i == 4: break if context == "help_not_attempted_quiz": text = "**Not attempted quizzes are: ** \n\n " + text elif context == "help_passed_quiz": text = "**Passed quizzes are: ** \n\n " + text else: text = "**Failed quizzes are: ** \n\n " + text return text except Exception as e: logger.exception(f"Parsing of API resuts failed") return None