| from datetime import datetime |
| import requests |
| import json |
| from utils.common import ACCOUNT_ID, BASE_URL, HEADER, LOCATION_ID |
|
|
|
|
| get_booking_summary_tool = { |
| "type": "function", |
| "function": { |
| "name": "GetBookingSummary", |
| "description": "Fetches a summary of bookings for a specific location, optionally filtered by date range. " |
| "Also in case of students attendance question we will call this function", |
| "parameters": { |
| "type": "object", |
| "properties": { |
| "location_id": { |
| "type": "string", |
| "description": "ID of the location to fetch booking summary for.", |
| "default": LOCATION_ID |
| }, |
| "date_from": { |
| "type": "string", |
| "format": "date", |
| "description": "Optional start date for the booking summary in YYYY-MM-DD format.", |
| "default": datetime.now().strftime('%Y-%m-%d') |
| }, |
| "date_to": { |
| "type": "string", |
| "format": "date", |
| "description": "Optional end date for the booking summary in YYYY-MM-DD format.", |
| "default": datetime.now().strftime('%Y-%m-%d') |
| } |
| }, |
| "required": ["location_id", "date_from", "date_to"] |
| } |
| } |
| } |
|
|
|
|
| def GetBookingSummary(location_id=LOCATION_ID, date_from=None, date_to=None): |
| """Fetch and print the summary of bookings for a specific location, with date range defaulting to today's date.""" |
|
|
| if date_from is None: |
| date_from = datetime.today().strftime('%Y-%m-%d') |
| if date_to is None: |
| date_to = datetime.today().strftime('%Y-%m-%d') |
|
|
| url = f"{BASE_URL}location/{location_id}/bookings/summary" |
|
|
| |
| params = { |
| "dateFrom": date_from, |
| "dateTo": date_to |
| } |
|
|
| try: |
| response = requests.get(url, headers=HEADER, params=params) |
| response.raise_for_status() |
| response_data = response.json() |
| formatted_response = json.dumps(response_data, indent=2) |
| return formatted_response |
| except requests.RequestException as e: |
| return f"Error making API request: {str(e)}" |
|
|
|
|