Spaces:
Sleeping
Sleeping
kevindiependaele commited on
Commit ·
4a5001f
1
Parent(s): baa37e5
fix tz
Browse files- tools/weather_api.py +5 -1
tools/weather_api.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
from typing import Dict
|
| 3 |
from datetime import datetime
|
|
|
|
| 4 |
|
| 5 |
from smolagents.tools import Tool
|
| 6 |
|
|
@@ -13,6 +14,9 @@ class WeatherApiTool(Tool):
|
|
| 13 |
def __init__(self, *args, **kwargs):
|
| 14 |
super().__init__(*args, **kwargs)
|
| 15 |
self.api_key = os.environ.get("OPEN_WEATHER_MAP_API_KEY")
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def forward(self, location: str, date: str) -> Dict:
|
| 18 |
import requests
|
|
@@ -46,7 +50,7 @@ class WeatherApiTool(Tool):
|
|
| 46 |
|
| 47 |
# Extract the weather data for the specified date
|
| 48 |
date_obj = datetime.strptime(date, "%Y-%m-%d")
|
| 49 |
-
date_obj =
|
| 50 |
epoch = date_obj.timestamp()
|
| 51 |
print(f"Epoch: {epoch}")
|
| 52 |
# for day in weather_data["daily"]:
|
|
|
|
| 1 |
import os
|
| 2 |
from typing import Dict
|
| 3 |
from datetime import datetime
|
| 4 |
+
import pytz
|
| 5 |
|
| 6 |
from smolagents.tools import Tool
|
| 7 |
|
|
|
|
| 14 |
def __init__(self, *args, **kwargs):
|
| 15 |
super().__init__(*args, **kwargs)
|
| 16 |
self.api_key = os.environ.get("OPEN_WEATHER_MAP_API_KEY")
|
| 17 |
+
|
| 18 |
+
# TODO: get the timezone from the location
|
| 19 |
+
self.local_tz = pytz.timezone("Europe/Brussels")
|
| 20 |
|
| 21 |
def forward(self, location: str, date: str) -> Dict:
|
| 22 |
import requests
|
|
|
|
| 50 |
|
| 51 |
# Extract the weather data for the specified date
|
| 52 |
date_obj = datetime.strptime(date, "%Y-%m-%d")
|
| 53 |
+
date_obj = self.local_tz.localize(date_obj)
|
| 54 |
epoch = date_obj.timestamp()
|
| 55 |
print(f"Epoch: {epoch}")
|
| 56 |
# for day in weather_data["daily"]:
|