def test_no_rain_expected(requests_mock: Mock) -> None: """Test datecomputation when rain is expected within the hour.""" client = MeteoFranceClient() requests_mock.request( "get", f"{METEOFRANCE_API_URL}/rain", json={ "position": { "lat": 48.807166, "lon": 2.239895, "alti": 76, "name": "Meudon", "country": "FR - France", "dept": "92", "timezone": "Europe/Paris", }, "updated_on": 1589995200, "quality": 0, "forecast": [ {"dt": 1589996100, "rain": 1, "desc": "Temps sec"}, {"dt": 1589996400, "rain": 1, "desc": "Temps sec"}, {"dt": 1589996700, "rain": 1, "desc": "Temps sec"}, {"dt": 1589997000, "rain": 1, "desc": "Temps sec"}, {"dt": 1589997300, "rain": 1, "desc": "Temps sec"}, {"dt": 1589997600, "rain": 1, "desc": "Temps sec"}, {"dt": 1589998200, "rain": 1, "desc": "Temps sec"}, {"dt": 1589998800, "rain": 1, "desc": "Temps sec"}, {"dt": 1589999400, "rain": 1, "desc": "Temps sec"}, ], }, ) rain = client.get_rain(latitude=48.8075, longitude=2.24028) assert rain.next_rain_date_locale() is None
def getPluieDansLheureLatLon(lat, lon) : # Init client client = MeteoFranceClient() # Search a location from name. # Fetch weather forecast for the location my_place_weather_forecast = client.get_forecast(lat, lon) # Get the daily forecast my_place_daily_forecast = my_place_weather_forecast.daily_forecast # If rain in the hour forecast is available, get it. print (my_place_weather_forecast.position["rain_product_available"] ) if my_place_weather_forecast.position["rain_product_available"] == 1: my_place_rain_forecast = client.get_rain(lat, lon) next_rain_dt = my_place_rain_forecast.next_rain_date_locale() if not next_rain_dt: rain_status = "Pas de pluie prévu dans l'heure" else: rain_status = next_rain_dt.strftime("%H:%M") else: rain_status = "Absence de données." return rain_status
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_rain(): """Test rain forecast on a covered zone.""" client = MeteoFranceClient() rain = client.get_rain(latitude=48.8075, longitude=2.24028) assert type(rain.position) == dict assert type(rain.updated_on) == int assert type(rain.quality) == int assert "rain" in rain.forecast[0].keys()
def test_rain_expected(requests_mock: Mock) -> None: """Test datecomputation when rain is expected within the hour.""" client = MeteoFranceClient() requests_mock.request( "get", f"{METEOFRANCE_API_URL}/rain", json={ "position": { "lat": 48.807166, "lon": 2.239895, "alti": 76, "name": "Meudon", "country": "FR - France", "dept": "92", "timezone": "Europe/Paris", }, "updated_on": 1589995200, "quality": 0, "forecast": [ {"dt": 1589996100, "rain": 1, "desc": "Temps sec"}, {"dt": 1589996400, "rain": 1, "desc": "Temps sec"}, {"dt": 1589996700, "rain": 1, "desc": "Temps sec"}, {"dt": 1589997000, "rain": 2, "desc": "Pluie faible"}, {"dt": 1589997300, "rain": 3, "desc": "Pluie modérée"}, {"dt": 1589997600, "rain": 2, "desc": "Pluie faible"}, {"dt": 1589998200, "rain": 1, "desc": "Temps sec"}, {"dt": 1589998800, "rain": 1, "desc": "Temps sec"}, {"dt": 1589999400, "rain": 1, "desc": "Temps sec"}, ], }, ) rain = client.get_rain(latitude=48.8075, longitude=2.24028) date_rain = rain.next_rain_date_locale() assert str(date_rain) == "2020-05-20 19:50:00+02:00" assert ( str(rain.timestamp_to_locale_time(rain.forecast[3]["dt"])) == "2020-05-20 19:50:00+02:00" )
def test_rain_not_covered(): """Test rain forecast result on a non covered zone.""" client = MeteoFranceClient() with pytest.raises(requests.HTTPError, match=r"400 .*"): client.get_rain(latitude=45.508, longitude=-73.58)
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. my_place_weather_alerts = client.get_warning_current_phenomenoms(my_place.admin2) readable_warnings = readeable_phenomenoms_dict( my_place_weather_alerts.phenomenons_max_colors )