Spaces:
Sleeping
Sleeping
Update app.py
Browse filesFix date conversion logic
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
from meteostat import Point, Daily
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
@@ -37,13 +38,16 @@ def get_current_temperatur_on_location(lat: float, long: float, day: str)-> str:
|
|
| 37 |
|
| 38 |
#Convert location to Point
|
| 39 |
# Create Point for New York, NY
|
| 40 |
-
location = Point(
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
data = Daily(location, start, end)
|
| 45 |
data = data.fetch()
|
| 46 |
-
|
| 47 |
except Exception as e:
|
| 48 |
return f"Error fetching temperatur for location '{location}': {str(e)}"
|
| 49 |
|
|
|
|
| 5 |
import yaml
|
| 6 |
from meteostat import Point, Daily
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
+
from datetime import timedelta
|
| 9 |
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
|
|
|
| 38 |
|
| 39 |
#Convert location to Point
|
| 40 |
# Create Point for New York, NY
|
| 41 |
+
location = Point(lat, long) # NYC
|
| 42 |
+
date_str = day #on format"2022-06-01"
|
| 43 |
+
date_obj = datetime.strptime(date_str, "%Y-%m-%d")
|
| 44 |
+
start = datetime(date_obj)
|
| 45 |
+
next_day = date_obj + timedelta(days=1)
|
| 46 |
+
end = datetime(next_day)
|
| 47 |
|
| 48 |
data = Daily(location, start, end)
|
| 49 |
data = data.fetch()
|
| 50 |
+
return f"Temperature on location {lat,long} is {data}"
|
| 51 |
except Exception as e:
|
| 52 |
return f"Error fetching temperatur for location '{location}': {str(e)}"
|
| 53 |
|