Skip to content

Instantly share code, notes, and snippets.

@elijahbenizzy
Created September 27, 2024 23:36
Show Gist options
  • Save elijahbenizzy/b687de29b2a91f06115e49b307015967 to your computer and use it in GitHub Desktop.
Save elijahbenizzy/b687de29b2a91f06115e49b307015967 to your computer and use it in GitHub Desktop.
def _weather_tool(latitude: float, longitude: float) -> dict:
"""Queries the weather for a given latitude and longitude."""
api_key = os.environ.get("TOMORROW_API_KEY")
url = f"https://api.tomorrow.io/v4/weather/forecast?location={latitude},{longitude}&apikey={api_key}"
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
return response.json()
else:
# Handle errors (e.g., invalid API key, rate limiting, etc.)
return {"error": f"Failed to get weather data. Status code: {response.status_code}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment