Exemple #1
0
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
Exemple #2
0
def test_currentphenomenons_with_coastal_bulletin(dep, res):
    """Test getting a complete basic bulletin for coastal department."""
    client = MeteoFranceClient()

    current_phenomenoms = client.get_warning_current_phenomenoms(
        domain=dep, depth=1, with_costal_bulletin=True)
    has_coastal_phenomenom = any(
        phenomenom["phenomenon_id"] == 9
        for phenomenom in current_phenomenoms.phenomenons_max_colors)
    assert has_coastal_phenomenom == res
Exemple #3
0
def test_currentphenomenons(requests_mock):
    """Test basic weather alert results from API."""
    client = MeteoFranceClient()

    requests_mock.request(
        "get",
        f"{METEOFRANCE_API_URL}/warning/currentphenomenons",
        json={
            "update_time":
            1591279200,
            "end_validity_time":
            1591365600,
            "domain_id":
            "32",
            "phenomenons_max_colors": [
                {
                    "phenomenon_id": 6,
                    "phenomenon_max_color_id": 1
                },
                {
                    "phenomenon_id": 4,
                    "phenomenon_max_color_id": 1
                },
                {
                    "phenomenon_id": 5,
                    "phenomenon_max_color_id": 3
                },
                {
                    "phenomenon_id": 2,
                    "phenomenon_max_color_id": 1
                },
                {
                    "phenomenon_id": 1,
                    "phenomenon_max_color_id": 1
                },
                {
                    "phenomenon_id": 3,
                    "phenomenon_max_color_id": 2
                },
            ],
        },
    )

    current_phenomenoms = client.get_warning_current_phenomenoms(domain="32",
                                                                 depth=1)

    assert type(current_phenomenoms.update_time) == int
    assert type(current_phenomenoms.end_validity_time) == int
    assert type(current_phenomenoms.domain_id) == str
    assert "phenomenon_id" in current_phenomenoms.phenomenons_max_colors[
        0].keys()
    assert current_phenomenoms.get_domain_max_color() == 3
Exemple #4
0
# 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
)

print (readable_warnings)