예제 #1
0
        private async void Chargement(string t)
        {
            using (var repo = new Connector(true)){}

            using (var repo = new APIRecuperator())
            {
                mr = await repo.GetMeteoAsync(t);

                Ville              = mr.city_info.name;
                Date               = $"{mr.current_condition.date} - {mr.current_condition.hour}";
                Temp               = $"{mr.current_condition.tmp}°C";
                Humidite           = $"{mr.current_condition.humidity}%";
                Condition          = mr.current_condition.condition;
                ConditionImg       = mr.current_condition.icon_big;
                ImgHuit            = mr.fcst_day_0.hourly_data._8H00.ICON;
                ImgDouze           = mr.fcst_day_0.hourly_data._12H00.ICON;
                ImgSeize           = mr.fcst_day_0.hourly_data._16H00.ICON;
                ImgVingt           = mr.fcst_day_0.hourly_data._20H00.ICON;
                ImgVingtTrois      = mr.fcst_day_0.hourly_data._23H00.ICON;
                TempHuit           = $"{mr.fcst_day_0.hourly_data._8H00.TMP2m}°";
                TempDouze          = $"{mr.fcst_day_0.hourly_data._12H00.TMP2m}°";
                TempSeize          = $"{mr.fcst_day_0.hourly_data._16H00.TMP2m}°";
                TempVingt          = $"{mr.fcst_day_0.hourly_data._20H00.TMP2m}°";
                TempVingtTrois     = $"{mr.fcst_day_0.hourly_data._23H00.TMP2m}°";
                HumiditeHuit       = $"{mr.fcst_day_0.hourly_data._8H00.RH2m}%";
                HumiditeDouze      = $"{mr.fcst_day_0.hourly_data._12H00.RH2m}%";
                HumiditeSeize      = $"{mr.fcst_day_0.hourly_data._16H00.RH2m}%";
                HumiditeVingt      = $"{mr.fcst_day_0.hourly_data._20H00.RH2m}%";
                HumiditeVingtTrois = $"{mr.fcst_day_0.hourly_data._23H00.RH2m}%";
                Jour1              = mr.fcst_day_1.day_short;
                Jour2              = mr.fcst_day_2.day_short;
                Jour3              = mr.fcst_day_3.day_short;
                Jour4              = mr.fcst_day_4.day_short;
                ImgJour0           = mr.fcst_day_0.icon;
                ImgJour1           = mr.fcst_day_1.icon;
                ImgJour2           = mr.fcst_day_2.icon;
                ImgJour3           = mr.fcst_day_3.icon;
                ImgJour4           = mr.fcst_day_4.icon;
                Jour0TempMax       = $"{mr.fcst_day_0.tmax}°";
                Jour0TempMin       = $"{mr.fcst_day_0.tmin}°";
                Jour1TempMax       = $"{mr.fcst_day_1.tmax}°";
                Jour1TempMin       = $"{mr.fcst_day_1.tmin}°";
                Jour2TempMax       = $"{mr.fcst_day_2.tmax}°";
                Jour2TempMin       = $"{mr.fcst_day_2.tmin}°";
                Jour3TempMax       = $"{mr.fcst_day_3.tmax}°";
                Jour3TempMin       = $"{mr.fcst_day_3.tmin}°";
                Jour4TempMax       = $"{mr.fcst_day_4.tmax}°";
                Jour4TempMin       = $"{mr.fcst_day_4.tmin}°";
            }
        }
예제 #2
0
        public async Task <MeteoRoot> GetMeteoAsync(string city)
        {
            HttpResponseMessage reponse = client.GetAsync($"https://www.prevision-meteo.ch/services/json/{city}").Result;

            if (reponse.IsSuccessStatusCode)
            {
                MeteoRoot mr = await reponse.Content.ReadAsAsync <MeteoRoot>();

                if (mr.city_info != null)
                {
                    return(mr);
                }
            }
            else
            {
                throw new Exception($"Erreur serveur : {(int)reponse.StatusCode}\n{reponse.ReasonPhrase}");
            }
            throw new Exception($"Erreur de connexion");
        }