def test_forecast_world(): """Test weather forecast results from API.""" client = MeteoFranceClient() weather_forecast = client.get_forecast(latitude=45.5016889, longitude=73.567256) now_ts = int(time.time()) 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 not weather_forecast.probability_forecast assert "clouds" in weather_forecast.forecast[0].keys() assert ( type( weather_forecast.timestamp_to_locale_time( weather_forecast.daily_forecast[0]["dt"] ) ) == datetime ) assert abs(weather_forecast.nearest_forecast["dt"] - now_ts) == min( abs(x["dt"] - now_ts) for x in weather_forecast.forecast ) assert ( weather_forecast.current_forecast["dt"] == weather_forecast.nearest_forecast["dt"] ) assert ( weather_forecast.today_forecast["dt"] == weather_forecast.daily_forecast[0]["dt"] )
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_forecast_france(): """Test weather forecast results from API.""" client = MeteoFranceClient() weather_forecast = client.get_forecast(latitude=48.8075, longitude=2.24028) now_ts = int(time.time()) 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 ) assert abs(weather_forecast.nearest_forecast["dt"] - now_ts) <= 30 * 60 assert now_ts - 3600 <= weather_forecast.current_forecast["dt"] <= now_ts assert ( weather_forecast.today_forecast["dt"] == weather_forecast.daily_forecast[0]["dt"] )
def getWind(ville): client = MeteoFranceClient() my_place = rechercheLatLong.getLatLongFromCityName(ville) jsonObj = client.get_forecast(my_place.latitude, my_place.longitude) premier= jsonObj.forecast[12] test = premier['wind'] dt = premier['dt'] time = datetime.utcfromtimestamp(dt).strftime('%d-%m-%Y %H:%M:%S') return ("la vitesse du vent à " + str(time) + " est de " + str(test['speed']*3600/1000) +" km/h avec une direction de " + str(test['direction']) + " degrée")