function Find_Weather_Station($lat, $long) { /* Making API calls per minute for a day */ $URL = 'http://api.openweathermap.org/data/2.5/station/find?lat=' . $lat . '&lon=' . $long . '&cnt=1'; $jsonResult = file_get_contents($URL); $result = json_decode($jsonResult, true); $station_id = $result[0]['station']['id']; $station_lat = $result[0]['station']['coord']['lat']; $station_long = $result[0]['station']['coord']['lon']; write_weather_header(); Fetch_Weather_Data($station_lat, $station_long); }
function Fetch_Weather_Data($station_lat, $station_long) { $URL = 'https://api.worldweatheronline.com/free/v2/weather.ashx?key=aa9967b205f647292c8eb466b7b8d&q=' . $station_lat . ',' . $station_long . '&num_of_days=5&tp=3&format=json&includeLocation=yes&cc=no'; $jsonResult = file_get_contents($URL); $result = json_decode($jsonResult, true); //print_r($result); $TotalResult = count($result['data']['weather']); $TotalCount = 0; while ($TotalCount < $TotalResult) { $HourlyCount = 0; $Forecast_date = $result['data']['weather'][$TotalCount]['date']; write_weather_header($Forecast_date); $TotalHourlyCount = count($result['data']['weather'][$TotalCount]['hourly']); while ($HourlyCount < $TotalHourlyCount) { $array = convertMultiDimJsonToAssoc($result['data']['weather'][$TotalCount]['hourly'][$HourlyCount]); print_r($array); write_weather_data($array, $Forecast_date); $HourlyCount++; } $TotalCount++; } }