def test_places_print() -> None: """Test different way to print Places class.""" client = MeteoFranceClient() place_in_france = client.search_places("montreal")[0] place_not_in_france = client.search_places("montreal", "45.50884", "-73.58")[0] assert (repr(place_in_france) == "<Place(name=Montréal, country=FR, admin=Languedoc-Roussillon)>") assert str(place_in_france) == "Montréal - Languedoc-Roussillon (11) - FR" assert (repr(place_not_in_france) == "<Place(name=Montréal, country=CA, admin=Quebec)>") assert str(place_not_in_france) == "Montréal - Quebec - CA" assert f"I live in {place_not_in_france}" == "I live in Montréal - Quebec - CA"
def get(self, request, *args, **kwargs): json_item = {} json_places = [] context = self.get_context_data(**kwargs) if "q" in request.GET: search_location = request.GET["q"] client = MeteoFranceClient() list_places = client.search_places(search_location) for one_place in list_places: # correct bad json returned my MeteoFrance + admin is not # always there if "name" in one_place.raw_data: one_place.raw_data["name"] = one_place.raw_data[ "name" ].replace("'", " ") if "admin" in one_place.raw_data: one_place.raw_data["admin"] = one_place.raw_data[ "admin" ].replace("'", " ") json_item["value"] = str(one_place.raw_data) json_item["text"] = one_place.__str__() json_places.append(json_item) json_item = {} return JsonResponse(json_places, status=200, safe=False) return render(request, SettingsView.template_name, context=context)
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_places_not_found() -> None: """Test when no places are found.""" client = MeteoFranceClient() list_places = client.search_places("sqdmfkjdsmkf") assert not list_places
def getLatLongFromCityName(ville): client = MeteoFranceClient() list_places = client.search_places(ville) my_place = list_places[0] position = PositionLatLong() position.latitude = my_place.latitude position.longitude = my_place.longitude return position
def test_places_with_gps() -> None: """Test a place search by specifying a GPS point to search arround.""" client = MeteoFranceClient() list_places = client.search_places("montreal", "45.50884", "-73.58") assert list_places place = list_places[0] assert place.name == "Montréal" assert place.country == "CA" assert place.admin == "Quebec" assert place.admin2 == "06"
def test_places() -> None: """Test for simple seach of Place.""" client = MeteoFranceClient() list_places = client.search_places("montreal") assert list_places place = list_places[0] assert place.insee assert place.latitude assert place.longitude assert place.postal_code assert place.name == "Montréal" assert place.country == "FR" assert place.admin == "Languedoc-Roussillon" assert place.admin2 == "11"
def getMeteoMarine(ville): client = MeteoFranceClient() list_places = client.search_places(ville) my_place = list_places[0] url_weather = "http://ws.meteofrance.com/ws//getDetail/france/"+ str(my_place.insee) + "0.json" #url_weather = "http://ws.meteofrance.com/ws//getDetail/france/290190.json" print (url_weather) r_weather = requests.get(url_weather) data = r_weather.json() result =data['result'] res_Ville = result['ville'] nomVille = res_Ville['nom'] bulletinCote = res_Ville['bulletinCote'] print(str(nomVille) + "/" + str(bulletinCote)) # print(result) resume_today = result['resumes']['0_resume'] #print(resume_today) descr = resume_today["description"] print (descr) returnedStr = "" if (bulletinCote == False): returnedStr = "Je ne trouve pas de bulletin cotier pour '"+nomVille + "'. " elif (bulletinCote == True): returnedStr = returnedStr + "Bulletin cotier de '"+nomVille + "', " date = int(resume_today['date']) #timestamp = 1602354456 #dt_object = datetime.fromtimestamp(timestamp) #print("dt_object =", dt_object) tutu = datetime.fromtimestamp((date/1000)) #gros hack... heure = int(tutu.strftime("%H")) if (bulletinCote == True): if heure >= 22 : returnedStr = returnedStr + " Nuit. " elif heure >= 18: returnedStr = returnedStr + " Soir. " elif heure >= 12: returnedStr = returnedStr + " Après-midi. " else: returnedStr = returnedStr + " Matin. " dateStr = tutu.strftime("%A %e %B") print (dateStr) returnedStr = returnedStr + "Prévisions pour la journée du " + dateStr +" ." ventForce = int(resume_today['vitesseVent']) forceRafales = int(resume_today['forceRafales']) directionVent = int(resume_today['directionVent']) if (directionVent > 315) : directionVentStr = " Nord Nord Ouest" elif (directionVent == 315) : directionVentStr = " Nord Ouest" elif (directionVent > 270) : directionVentStr = " Nord Ouest" elif (directionVent == 270) : directionVentStr = " Ouest" elif (directionVent > 225) : directionVentStr = " Ouest Sud Ouest" elif (directionVent == 225) : directionVentStr = " Sud Ouest" elif (directionVent > 180) : directionVentStr = " Sud Sud Ouest" elif (directionVent == 180) : directionVentStr = " Sud" elif (directionVent > 135) : directionVentStr = " Sud Sud Est" elif (directionVent == 135) : directionVentStr = " Sud Est" elif (directionVent > 90) : directionVentStr = " Est Sud Est" elif (directionVent == 90) : directionVentStr = " Est" elif (directionVent > 45) : directionVentStr = " Est Nord Est" elif (directionVent == 45) : directionVentStr = " Nord Est" elif (directionVent > 0 ) : directionVentStr = " Nord Nord Est" elif (directionVent == 0 ) : directionVentStr = " Nord" returnedStr = returnedStr + " VENT, direction " + directionVentStr + " de " + str(ventForce) + " km/h " if (forceRafales > 0) : returnedStr = returnedStr + " avec des rafales à " + str(forceRafales) + " km/h." #" VENT : Nord-Ouest 4 à 5, fraichissant 5 à 6 en Manche l'après-midi. #TODO # MER : agitée. HOULE : Ouest à Nord-Ouest 2 m sur pointe Bretagne. #TODO # TEMPS : Ciel nuageux.. returnedStr = returnedStr + ". " + getConditionCielCourant(nomVille) probaPluie = resume_today['probaPluie'] print (probaPluie) if (probaPluie is int and probaPluie > 0) : returnedStr = returnedStr + " avec probabilité de pluie de " + str(probaPluie) + "%." # VISIBILITE : Bonne." print (returnedStr) return returnedStr
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.