Skip to content

Instantly share code, notes, and snippets.

@cgawron
Created October 6, 2023 11:25
Show Gist options
  • Save cgawron/794128fe13456396fa5434b348adacd1 to your computer and use it in GitHub Desktop.
Save cgawron/794128fe13456396fa5434b348adacd1 to your computer and use it in GitHub Desktop.
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