private void Crawl(Dictionary <string, string> dictionary) { PastWeatherInput pastWeatherInput = new PastWeatherInput(); pastWeatherInput.query = CITY; pastWeatherInput.format = FORMAT; foreach (var item in dictionary) { pastWeatherInput.date = item.Key; pastWeatherInput.enddate = item.Value; WWOWeatherData weatherData = worker.GetPastWeather(pastWeatherInput); weatherDatas.Add(weatherData); lock (lockObject) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Az alábbi év, hónap időjárási adata le lett töltve: " + item.Key); } //ImportantWeatherData important = new ImportantWeatherData(weatherData); foreach (var i in weatherData.data.weather) { SimpleWeather simple = new SimpleWeather(i); importantWeatherDatas.Add(simple); } } //ImportantWeatherData important; //foreach (var item in weatherDatas) //{ // important = new ImportantWeatherData(item); // importantWeatherDatas.Add(important); //} }
/// <summary> /// This event handler method calls /// the ProcessHistoricalData method of the ProcessorClass class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DisplayHistoricalDataButton_Click(object sender, EventArgs e) { //ProcessorClass.ProcessHistoricalData(); try { String location = SearchTextBox.Text.ToString(); PastWeatherInput input = new PastWeatherInput(); input.query = location; input.date = "2013-03-01"; input.enddate = "2018-03-03"; input.format = "JSON"; /* Call the GetPastWeather method and pass in input parameters*/ API_Implementation api = new API_Implementation(); PastWeather pastWeather = api.GetPastWeather(input); /*Display Results*/ DisplayResultsTextBox.Text = "\r\n Date: " + pastWeather.data.weather[0].date; DisplayResultsTextBox.Text += "\r\n Max Temp(C): " + pastWeather.data.weather[0].maxtempC; DisplayResultsTextBox.Text += "\r\n Max Temp(F): " + pastWeather.data.weather[0].maxtempF; DisplayResultsTextBox.Text += "\r\n Min Temp(C): " + pastWeather.data.weather[0].mintempC; DisplayResultsTextBox.Text += "\r\n Min Temp(F): " + pastWeather.data.weather[0].mintempF; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + pastWeather.data.weather[0].hourly[0].cloudcover; DisplayResultsTextBox.Text += "\r\n Humidity: " + pastWeather.data.weather[0].hourly[0].humidity; DisplayResultsTextBox.Text += "\r\n Pressure: " + pastWeather.data.weather[0].hourly[0].pressure; DisplayResultsTextBox.Text += "\r\n Visibility: " + pastWeather.data.weather[0].hourly[0].visibility; DisplayResultsTextBox.Text += "\r\n Wind Speed: " + pastWeather.data.weather[0].hourly[0].windspeedMiles; } catch (Exception ex) { ex.GetBaseException(); } }
public PastWeather GetPastWeather(PastWeatherInput input) { // create URL based on input paramters string apiURL = ApiBaseURL + "past-weather.ashx?q=" + input.query + "&format=" + input.format + "&extra=" + input.extra + "&enddate=" + input.enddate + "&date=" + input.date + "&includelocation=" + input.includelocation + "&callback=" + input.callback + "&key=" + PremiumAPIKey; // get the web response string result = new RequestHandler(apiURL).Process(); // deserialize the json output into the c#classes created earlier PastWeather pWeather = null; if (result != null) { result = result.Replace("No moonset", "11:47 AM"); } try { pWeather = (PastWeather) new JavaScriptSerializer().Deserialize(result, typeof(PastWeather)); } catch (FormatException ex) { } return(pWeather); }
public SerialSolution() { input = new PastWeatherInput(); input.query = CITY; input.format = FORMAT; WeatherDatas = new List <WWOWeatherData>(); }
/// <summary> /// This method consumes the WorldWeather Premium API /// to show past weather data of any given location /// for a given period /// </summary> public void GetHistoricalData() { try { String location = SearchTextBox.Text.ToString(); PastWeatherInput input = new PastWeatherInput(); input.query = location; input.date = "2017-01-01"; input.enddate = "2019-01-01"; input.format = "JSON"; /* Call the GetPastWeather method and pass in input parameters*/ API_Implementation api = new API_Implementation(); PastWeather pastWeather = api.GetPastWeather(input); /*Display Results*/ DisplayResultsTextBox.Text = "\r\n Date: " + pastWeather.data.weather[0].date; DisplayResultsTextBox.Text += "\r\n Max Temp(C): " + pastWeather.data.weather[0].maxtempC; DisplayResultsTextBox.Text += "\r\n Max Temp(F): " + pastWeather.data.weather[0].maxtempF; DisplayResultsTextBox.Text += "\r\n Min Temp(C): " + pastWeather.data.weather[0].mintempC; DisplayResultsTextBox.Text += "\r\n Min Temp(F): " + pastWeather.data.weather[0].mintempF; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + pastWeather.data.weather[0].hourly[0].cloudcover; } catch (Exception ex) { ex.GetBaseException(); } }
public SemaphoreSolution(string[] yearDataStart, string[] YearDataEnd, string yearName) { this.Ev = yearName; this.dataStart = yearDataStart; this.dataEnd = YearDataEnd; inputWeather = new PastWeatherInput(); inputWeather.query = CITY; inputWeather.format = FORMAT; WeatherDatas = new List <WWOWeatherData>(); }
public SemaphoreSolution(string inputStart, string inputEnd, string ev) { //this.data = input; this.Ev = ev; inputWeather = new PastWeatherInput(); inputWeather.query = CITY; inputWeather.format = FORMAT; inputWeather.date = inputStart; inputWeather.enddate = inputEnd; WeatherDatas = new List <WWOWeatherData>(); }
public string PremiumAPIKey = ""; //Az api kulcs helye public WWOWeatherData GetPastWeather(PastWeatherInput input) { // create URL based on input paramters string apiURL = ApiBaseURL + "past-weather.ashx?q=" + input.query + "&format=" + input.format + "&extra=" + input.extra + "&enddate=" + input.enddate + "&date=" + input.date + "&includelocation=" + input.includelocation + "&callback=" + input.callback + "&key=" + PremiumAPIKey; string result = RequestHandler.Process(apiURL); //itt a json sorokból tesszük át a normál formátumba WWOWeatherData pastweather = (WWOWeatherData) new JavaScriptSerializer().Deserialize(result, typeof(WWOWeatherData)); return(pastweather); }
/// <summary> /// This method gets the historical /// weather data of a given location /// for a given period of time /// </summary> /// <param name="input"></param> /// <returns>weather history</returns> public PastWeather GetPastWeather(PastWeatherInput input) { /* Create URL based on input paramters */ string apiURL = ApiBaseURL + "past-weather.ashx?q=" + input.query + "&format=" + input.format + "&extra=" + input.extra + "&enddate=" + input.enddate + "&date=" + input.date + "&includelocation=" + input.includelocation + "&callback=" + input.callback + "&key=" + APIKey; /* Get the web response */ string result = RequestHandler.Process(apiURL); /* Serialize the json output and parse in the helper class */ PastWeather pWeather = (PastWeather) new JavaScriptSerializer().Deserialize(result, typeof(PastWeather)); return(pWeather); }
private WeatherData GetInfo() { PastWeather pastWeather = null; WeatherData data = new WeatherData(); // set input parameters for the API LocalWeatherInput input = new LocalWeatherInput(); input.query = m_info_future.query; input.num_of_days = m_info_future.num_of_days; input.date = m_info_future.date; input.format = "JSON"; // call the local weather method with input parameters WorldWeatherOnlineAPI api = new WorldWeatherOnlineAPI(); LocalWeather localWeather = api.GetLocalWeather(input); if (m_info_historical != null) { //request past data if needed PastWeatherInput h_input = new PastWeatherInput(); h_input.query = m_info_historical.query; h_input.date = m_info_historical.date; h_input.enddate = m_info_historical.enddate; h_input.format = "JSON"; pastWeather = api.GetPastWeather(h_input); } //set data in datastore based on which kind of datastore refresh was requested if (m_reftype == RefreshType.AddLeft) { DataStore.Instance().AddLeft(pastWeather); } else if (m_reftype == RefreshType.AddLeft) { DataStore.Instance().AddRight(localWeather); } else { DataStore.Instance().SetWeather(localWeather, pastWeather); } return(data); }
public void Test_HistoricalDataMethod() { PastWeatherInput input = new PastWeatherInput(); Assert.IsNull(input.date); }