get_pending_events
Retrieve upcoming Moodle calendar events and deadlines to help students track academic schedules and pending tasks.
Instructions
Get upcoming events and deadlines from Moodle calendar.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:143-151 (handler)The main handler function for the 'get_pending_events' tool. It calls the MUSTerClient method and formats the events into a list of dictionaries.def tool_get_pending_events() -> List[Dict[str, str]]: try: events = muster_client.get_pending_events() return [ {"name": event.name, "course": event.course, "due_date": event.due_date, "url": event.url} for event in events ] except Exception as e: return [{"error": f"Failed to get pending events: {str(e)}"}]
- main.py:45-49 (schema)The input schema definition for the 'get_pending_events' tool, indicating it takes no parameters.Tool( name="get_pending_events", description="Get upcoming events and deadlines from Moodle calendar.", inputSchema={"type": "object", "properties": {}, "required": []}, ),
- main.py:211-212 (registration)Registration/dispatch logic in the call_tool handler that invokes the tool_get_pending_events function when the tool name matches.if name == "get_pending_events": return _wrap_json(tool_get_pending_events())
- MUSTerClient.py:375-481 (helper)Helper method in MUSTerClient class that performs the actual web scraping to retrieve pending events from the Moodle calendar page.def get_pending_events(self) -> List[Event]: """Get all pending events and assignment deadlines with detailed information.""" self._ensure_driver() self.heartBeat() if not self.logged_in: if not self.login(): raise Exception("Login required to get events.") events = [] try: # Navigate to upcoming events page self.driver.get(f"{MOODLE_URL}/calendar/view.php?view=upcoming") # Wait for events to load WebDriverWait(self.driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "[data-type='event']")) ) # Find all event containers event_elements = self.driver.find_elements(By.CSS_SELECTOR, "[data-type='event']") for element in event_elements: try: # Extract event name from header event_name = "" try: event_name = element.find_element(By.CSS_SELECTOR, "h3.name").text.strip() except Exception: # Fallback to data attribute event_name = element.get_attribute("data-event-title") or "" if not event_name: continue # Extract due date/time due_date = "" try: # Find the row containing the "When" icon date_row = element.find_element(By.XPATH, ".//div[@class='row'][.//i[@title='When']]") date_col = date_row.find_element(By.CSS_SELECTOR, ".col-11") due_date = date_col.text.strip() except Exception: pass # Extract event type event_type = "" try: # Find the row containing the "Event type" icon type_row = element.find_element(By.XPATH, ".//div[@class='row mt-1'][.//i[@title='Event type']]") type_col = type_row.find_element(By.CSS_SELECTOR, ".col-11") event_type = type_col.text.strip() except Exception: # Fallback to data attribute event_type = element.get_attribute("data-event-eventtype") or "unknown" # Extract course name and URL course_name = "" course_url = "" try: # Find the row containing the "Course" icon course_row = element.find_element(By.XPATH, ".//div[@class='row mt-1'][.//i[@title='Course']]") course_link = course_row.find_element(By.CSS_SELECTOR, ".col-11 a") course_name = course_link.text.strip() course_url = course_link.get_attribute("href") or "" except Exception: pass # Extract description (if available) description = "" try: desc_element = element.find_element(By.CSS_SELECTOR, ".description-content") description = desc_element.text.strip() except Exception: pass # Extract activity URL activity_url = "" try: activity_link = element.find_element(By.CSS_SELECTOR, ".card-footer a.card-link") activity_url = activity_link.get_attribute("href") or "" except Exception: pass # Create Event object event = Event( name=event_name, due_date=due_date, event_type=event_type, course=course_name, course_url=course_url, url=activity_url, description=description ) events.append(event) except Exception as e: print(f"Error parsing individual event: {e}") continue except TimeoutException: print("Timeout while waiting for events to load") except Exception as e: print(f"Error retrieving pending events: {e}") self.heartBeat() return events