AI_Agent_Hackathon / tools /weather_example.py
Hugo Bui
add weather tool
4160511 unverified
raw
history blame
1.45 kB
#!/usr/bin/env python3
"""
Exemple d'utilisation de l'outil météo (API gratuite OpenWeatherMap)
"""
from weather_tool import WeatherTool
from datetime import datetime, timedelta
def main():
# Initialiser l'outil météo (charge automatiquement la clé API depuis .env)
weather_tool = WeatherTool()
print("=== Exemples d'utilisation de l'outil météo ===\n")
# Exemple 1: Météo actuelle
print("1. Météo actuelle à Paris:")
result = weather_tool.forward("Paris")
print(result)
print("\n" + "="*50 + "\n")
# Exemple 2: Météo pour une date spécifique
print("2. Météo à Londres pour demain:")
tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d")
result = weather_tool.forward("London", date=tomorrow)
print(result)
print("\n" + "="*50 + "\n")
# Exemple 3: Météo pour un pays
print("3. Météo à Tokyo dans 3 jours:")
future_date = (datetime.now() + timedelta(days=3)).strftime("%Y-%m-%d")
result = weather_tool.forward("Tokyo", date=future_date)
print(result)
print("\n" + "="*50 + "\n")
# Exemple 4: Météo avec une clé API spécifique
print("4. Météo à Berlin (avec clé API personnalisée):")
# result = weather_tool.forward("Berlin", api_key="votre_cle_api_ici")
result = weather_tool.forward("Berlin") # Utilise la clé du .env
print(result)
if __name__ == "__main__":
main()