def test_workflow(city): """Test classical workflow usage with the Python library.""" # Init client client = MeteoFranceClient() # Search a location from name. list_places = client.search_places(city) my_place = list_places[0] # Fetch weather forecast for the location my_place_weather_forecast = client.get_forecast_for_place(my_place) # Get the daily forecast my_place_daily_forecast = my_place_weather_forecast.daily_forecast # If rain in the hour forecast is available, get it. if my_place_weather_forecast.position["rain_product_available"] == 1: my_place_rain_forecast = client.get_rain(my_place.latitude, my_place.longitude) next_rain_dt = my_place_rain_forecast.next_rain_date_locale() if not next_rain_dt: rain_status = "No rain expected in the following hour." else: rain_status = next_rain_dt.strftime("%H:%M") else: rain_status = "No rain forecast availble." # Fetch weather alerts. my_place_weather_alerts = client.get_warning_current_phenomenoms(my_place.admin2) readable_warnings = readeable_phenomenoms_dict( my_place_weather_alerts.phenomenons_max_colors ) assert type(my_place_daily_forecast) == list assert rain_status assert type(readable_warnings) == dict
def test_forecast_place() -> None: """Test weather forecast results from API.""" client = MeteoFranceClient() weather_forecast = client.get_forecast_for_place( place=Place(MOUNTAIN_CITY)) assert type(weather_forecast.position) == dict assert type(weather_forecast.updated_on) == int assert "T" in weather_forecast.daily_forecast[0].keys() assert "humidity" in weather_forecast.daily_forecast[0].keys() assert "rain" in weather_forecast.probability_forecast[0].keys() assert "clouds" in weather_forecast.forecast[0].keys() assert (type( weather_forecast.timestamp_to_locale_time( weather_forecast.daily_forecast[0]["dt"])) == datetime)
from meteofrance.client import MeteoFranceClient from meteofrance.helpers import readeable_phenomenoms_dict # Init client client = MeteoFranceClient() # Search a location from name. city = "Brest" list_places = client.search_places(city) my_place = list_places[0] # Fetch weather forecast for the location my_place_weather_forecast = client.get_forecast_for_place(my_place) # Get the daily forecast my_place_daily_forecast = my_place_weather_forecast.daily_forecast # If rain in the hour forecast is available, get it. if my_place_weather_forecast.position["rain_product_available"] == 1: my_place_rain_forecast = client.get_rain(my_place.latitude, my_place.longitude) next_rain_dt = my_place_rain_forecast.next_rain_date_locale() if not next_rain_dt: rain_status = "No rain expected in the following hour." else: rain_status = next_rain_dt.strftime("%H:%M") else: rain_status = "No rain forecast availble." print (rain_status) # Fetch weather alerts.