Created
October 6, 2023 11:25
-
-
Save cgawron/794128fe13456396fa5434b348adacd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import python_weather | |
import asyncio | |
class ActionCheckWeather(Action): | |
def name(self) -> Text: | |
return "action_check_weather" | |
async def run(self, dispatcher: CollectingDispatcher, | |
tracker: Tracker, | |
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: | |
async with python_weather.Client() as client: | |
# fetch a weather forecast from a city | |
city = "Iserlohn" | |
for blob in tracker.latest_message['entities']: | |
print(tracker.latest_message) | |
if blob['entity'] == 'place': | |
city = blob['value'] | |
weather = await client.get(city) | |
weathertext = "" | |
# get the weather forecast for a few days | |
for forecast in list(weather.forecasts)[:1]: | |
print(forecast) | |
weathertext += f"In {city} it es {forecast.temperature} Grad" | |
dispatcher.utter_message(text=weathertext) | |
return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment