Spaces:
Running on Zero
Running on Zero
Download tools/get_current_time_in_timezone.py from Ark4u/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 618 Bytes
-
https://huggingface.co/spaces/Ark4u/First_agent_template/resolve/main/tools/get_current_time_in_timezone.py
- Command line
-
hf download hf://spaces/Ark4u/First_agent_template/tools/get_current_time_in_timezone.py
-
curl -L -o get_current_time_in_timezone.py https://huggingface.co/spaces/Ark4u/First_agent_template/resolve/main/tools/get_current_time_in_timezone.py
618 Bytes
| import datetime | |
| import pytz | |
| from smolagents import tool | |
| def get_current_time_in_timezone(timezone: str) -> str: | |
| """A tool that fetches the current local time in a specified timezone. | |
| Args: | |
| timezone: A valid IANA timezone (e.g., 'America/New_York', 'Europe/Paris', 'Asia/Kolkata', 'UTC'). | |
| """ | |
| try: | |
| tz = pytz.timezone(timezone) | |
| local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S") | |
| return f"The current local time in {timezone} is: {local_time}" | |
| except Exception as e: | |
| return f"Error fetching time for timezone '{timezone}': {str(e)}" | |