Beispiel #1
0
        internal static string GetCityInfo(string city, string target)
        {
            if ((!city.Equals("呼市郊区")) && (!city.Equals("津市")) && (!city.Equals("沙市")))
            {
                city = city.Replace("省", "");
                city = city.Replace("市", "");
            }
            city = city.Replace(" ", "");
            city = city.Replace("\r", "");
            city = city.Replace("\n", "");

            target = target.Replace(" ", "");
            target = target.Replace("\r", "");
            target = target.Replace("\n", "");
            string ans = "";

            string url  = "https://ruiruiqq.hxlxz.com/weather.php?city=" + city + "&type=forecast";
            string temp = HttpClient.Get(url);

            if (temp.Equals("NoCity"))
            {
                return("未查询到指定城市 " + city + " 的信息");
            }

            JsonWeatherModel weather = (JsonWeatherModel)JsonConvert.DeserializeObject(temp, typeof(JsonWeatherModel));

            ans  = "城市 " + weather.c.c3 + "(" + weather.c.c2 + ") 的信息如下:" + Environment.NewLine;
            ans += "所在省市:" + weather.c.c7 + "省" + weather.c.c5 + "市" + "(" + weather.c.c6 + " " + weather.c.c4 + ")" + Environment.NewLine;
            ans += "区号:" + weather.c.c11 + ",邮编:" + weather.c.c12 + "。城市级别:" + weather.c.c10 + "级城市" + Environment.NewLine;
            ans += "经度:" + weather.c.c13 + ",纬度:" + weather.c.c14 + ",海拔:" + weather.c.c15 + "。雷达站" + weather.c.c16;
            return(ans);
        }
Beispiel #2
0
        public static string GetWeather(string city, string target)
        {
            if ((!city.Equals("呼市郊区")) && (!city.Equals("津市")) && (!city.Equals("沙市")))
            {
                city = city.Replace("省", "");
                city = city.Replace("市", "");
            }
            city = city.Replace(" ", "");
            city = city.Replace("\r", "");
            city = city.Replace("\n", "");

            target = target.Replace(" ", "");
            target = target.Replace("\r", "");
            target = target.Replace("\n", "");
            string ans = "";
            string url, temp;

            if (target.Equals("雅虎"))
            {
                url  = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20%28select%20woeid%20from%20geo.places%281%29%20where%20text=\"" + city + "\") and%20u=%22c%22&format=json";
                temp = HttpClient.Get(url);
                JsonYahooWeatherModel weather = (JsonYahooWeatherModel)JsonConvert.DeserializeObject(temp, typeof(JsonYahooWeatherModel));
                if (weather.query.results == null)
                {
                    return("未查询到指定城市 " + city + " 的天气信息");
                }
                else
                {
                    ans = weather.query.results.channel.description + "(请核对城市名是否正确)";
                    for (int i = 0; i < weather.query.results.channel.item.forecast.Count; i++)
                    {
                        ans = ans + Environment.NewLine + "周" + getYahooWeak(weather.query.results.channel.item.forecast[i].day) + ":" + getYahooWeatherCode(weather.query.results.channel.item.forecast[i].code) + ",最高气温:" + weather.query.results.channel.item.forecast[i].high + "摄氏度,最低气温:" + weather.query.results.channel.item.forecast[i].low + "摄氏度";
                    }
                    return(ans);
                }
            }
            if (target.Equals("指数"))
            {
                target = "index";
            }
            else
            {
                target = "forecast";
            }
            url  = "https://ruiruiqq.hxlxz.com/weather.php?city=" + city + "&type=" + target;
            temp = HttpClient.Get(url);
            if (temp.Equals("NoCity"))
            {
                return(GetWeather(city, "雅虎"));
            }

            if (target.Equals("forecast"))
            {
                JsonWeatherModel weather = (JsonWeatherModel)JsonConvert.DeserializeObject(temp, typeof(JsonWeatherModel));
                ans = "根据中国天气网于" + weather.f.f0 + "发布的气象预报," + weather.c.c3 + "的气象信息如下:" + Environment.NewLine;
                if (weather.f.f1[0].fa != null && !weather.f.f1[0].fa.Equals(""))
                {
                    ans = ans + "今天白天:" + SloveWeather(weather.f.f1[0].fa) + "," + weather.f.f1[0].fc + "摄氏度," + SloveWind(weather.f.f1[0].fe) + SloveWindPower(weather.f.f1[0].fg) + "。";
                }
                else
                {
                    ans = ans + "今天";
                }
                ans = ans + "晚上:" + SloveWeather(weather.f.f1[0].fb) + "," + weather.f.f1[0].fd + "摄氏度," + SloveWind(weather.f.f1[0].ff) + SloveWindPower(weather.f.f1[0].fh) + "。日出日落时间:" + weather.f.f1[0].fi + Environment.NewLine;
                ans = ans + "明天白天:" + SloveWeather(weather.f.f1[1].fa) + "," + weather.f.f1[1].fc + "摄氏度," + SloveWind(weather.f.f1[1].fe) + SloveWindPower(weather.f.f1[1].fg) + "。";
                ans = ans + "晚上:" + SloveWeather(weather.f.f1[1].fb) + "," + weather.f.f1[1].fd + "摄氏度," + SloveWind(weather.f.f1[1].ff) + SloveWindPower(weather.f.f1[1].fh) + "。日出日落时间:" + weather.f.f1[1].fi + Environment.NewLine;
                ans = ans + "后天白天:" + SloveWeather(weather.f.f1[2].fa) + "," + weather.f.f1[2].fc + "摄氏度," + SloveWind(weather.f.f1[2].fe) + SloveWindPower(weather.f.f1[2].fg) + "。";
                ans = ans + "晚上:" + SloveWeather(weather.f.f1[2].fb) + "," + weather.f.f1[2].fd + "摄氏度," + SloveWind(weather.f.f1[2].ff) + SloveWindPower(weather.f.f1[2].fh) + "。日出日落时间:" + weather.f.f1[2].fi;
            }
            else if (target.Equals("index"))
            {
                JsonWeatherIndexModel WeatherIndex = (JsonWeatherIndexModel)JsonConvert.DeserializeObject(temp, typeof(JsonWeatherIndexModel));
                ans = "根据中国天气网发布的气象预报," + city + "的气象信息如下:" + Environment.NewLine;
                ans = ans + WeatherIndex.i[0].i2 + ":" + WeatherIndex.i[0].i4 + ";" + WeatherIndex.i[0].i5 + Environment.NewLine;
                ans = ans + WeatherIndex.i[1].i2 + ":" + WeatherIndex.i[1].i4 + ";" + WeatherIndex.i[1].i5 + Environment.NewLine;
                ans = ans + WeatherIndex.i[2].i2 + ":" + WeatherIndex.i[2].i4 + ";" + WeatherIndex.i[2].i5;
            }
            return(ans);
        }