예제 #1
0
        //private static string get_Weather_InCity(string city)
        //{
        //    string api_key = "782792da0e998344afa4a6cc73d7e890";
        //    RESTClient rClient = new RESTClient();
        //    string txtRequestURI = "https://api.openweathermap.org/data/2.5/weather?q="+ city + "&appid=" + api_key;
        //    rClient.endPoint = txtRequestURI;
        //    string strJSON = string.Empty;
        //    strJSON = rClient.makeRequest();
        //    return strJSON;
        //}


        private static Weather_Model get_Weather_InCity(string city)
        {
            string     api_key       = "782792da0e998344afa4a6cc73d7e890";
            RESTClient rClient       = new RESTClient();
            string     txtRequestURI = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + api_key;

            rClient.endPoint = txtRequestURI;
            string strJSON = string.Empty;

            strJSON = rClient.makeRequest();
            Weather_Model myDeserializedClass = JsonConvert.DeserializeObject <Weather_Model>(strJSON);

            return(myDeserializedClass);
        }
예제 #2
0
 private static void operation(long chat_Id, string messageToBot)
 {
     if (messageToBot == "/datatime")
     {
         string send_message = DateTime.UtcNow.ToString();
         SendTextMessage(chat_Id, send_message);
         return;
     }
     if (messageToBot == "/json")
     {
         string send_message = cmdGO_Click();
         SendTextMessage(chat_Id, send_message);
         return;
     }
     if (messageToBot == "/weather")
     {
         id_weather = 1;
         SendTextMessage(chat_Id, "Write name of city");
         return;
     }
     else if (id_weather == 1)
     {
         id_weather = 0;
         Weather_Model Weather = get_Weather_InCity(messageToBot);
         if (Weather != null)
         {
             string response = "";
             response += Weather.name + "\n";
             response += "Weather: " + Weather.weather.ElementAt(0).description + "\n";
             response += "Cloud: " + Weather.clouds.all + "%\n";
             response += "Wind: " + Weather.wind.speed + " m/s\n";
             response += "Tempertatur: " + (Math.Round(Weather.main.temp - 273)).ToString() + " °C\n";
             string icon = Weather.weather.ElementAt(0).icon;
             SendPhotoMessage(chat_Id, response, icon);
         }
         SendTextMessage(chat_Id, "Error");
         return;
     }
     SendTextMessage(chat_Id, "Error");
 }