Код: Выделить всё
/**
* Получение погоды по ID города
* @param int $cityID ID города
*/
public function get_weather($cityID)
{
$rT = gg('ow_setting.round_temp');
$weather = app_openweather::GetJsonWeatherDataByCityID($cityID);
$curWeather = self::GetCurrentWeatherDataByCityID($cityID);
if ($weather->cod == "404" || $curWeather->cod == "404")
{
DebMes($weather->message);
return;
}
$fact = $curWeather->main;
$date = date("d.m.Y G:i:s T Y", $curWeather->dt);
sg('ow_fact.temperature', round($fact->temp,$rT));
sg('ow_fact.weather_type', $curWeather->weather[0]->description);
sg('ow_fact.wind_direction', $curWeather->wind->deg);
sg('ow_fact.wind_speed',$curWeather->wind->speed);
sg('ow_fact.humidity', $fact->humidity);
sg('ow_fact.pressure', $fact->pressure);
sg('ow_fact.pressure_mmhg', app_openweather::ConvertPressure($fact->pressure, "hpa", "mmhg", 2));
sg('ow_fact.image', $curWeather->weather[0]->icon);
sg('ow_fact.clouds', $curWeather->clouds->all);
sg('ow_fact.rain', isset($fact->rain) ? $fact->rain : '');
sg('ow_city.data_update', $date);
$sunInfo = $this->GetSunInfoByCityID($cityID);
if ($sunInfo)
{
$sunRise = $sunInfo["sunrise"];
$sunSet = $sunInfo["sunset"];
$dayLength = $sunSet - $sunRise;
sg('ow_fact.sunrise', $sunRise);
sg('ow_fact.sunset', $sunSet);
sg('ow_fact.day_length', $dayLength);
sg('ow_fact.transit', $sunInfo["transit"]);
sg('ow_fact.civil_twilight_begin', $sunInfo["civil_twilight_begin"]);
sg('ow_fact.civil_twilight_end', $sunInfo["civil_twilight_end"]);
}
$i = 0;
foreach($weather->list as $day)
{
$date = date("d.m.Y", $day->dt);
sg('ow_day'.$i.'.date', $date);
sg('ow_day'.$i.'.temperature', round(app_openweather::GetCurrTemp($day->temp),$rT));
sg('ow_day'.$i.'.temp_morn', round($day->temp->morn,$rT));
sg('ow_day'.$i.'.temp_day', round($day->temp->day,$rT));
sg('ow_day'.$i.'.eve', round($day->temp->eve,$rT));
sg('ow_day'.$i.'.temp_night', round($day->temp->night,$rT));
sg('ow_day'.$i.'.temp_min', round($day->temp->min,$rT));
sg('ow_day'.$i.'.temp_max', round($day->temp->max,$rT));
sg('ow_day'.$i.'.weather_type', $day->weather[0]->description);
sg('ow_day'.$i.'.wind_direction', $day->deg);
sg('ow_day'.$i.'.wind_speed', $day->speed);
sg('ow_day'.$i.'.humidity', $day->humidity);
sg('ow_day'.$i.'.pressure', $day->pressure);
sg('ow_day'.$i.'.pressure_mmhg', app_openweather::ConvertPressure($day->pressure, "hpa", "mmhg", 2));
sg('ow_day'.$i.'.image', $day->weather[0]->icon);
sg('ow_day'.$i.'.clouds', $day->clouds);
sg('ow_day'.$i.'.rain', isset($day->rain) ? $day->rain : 0);
sg('ow_day'.$i.'.snow', isset($day->snow) ? $day->snow : 0);
$curTimeStamp = strtotime('+' . $i . ' day', time());
$sunInfo = $this->GetSunInfoByCityID($cityID, $curTimeStamp);
if ($sunInfo)
{
$sunRise = $sunInfo["sunrise"];
$sunSet = $sunInfo["sunset"];
$dayLength = $sunSet - $sunRise;
sg('ow_day'.$i.'.sunrise', $sunRise);
sg('ow_day'.$i.'.sunset', $sunSet);
sg('ow_day'.$i.'.day_length', $dayLength);
sg('ow_day'.$i.'.transit', $sunInfo["transit"]);
sg('ow_day'.$i.'.civil_twilight_begin', $sunInfo["civil_twilight_begin"]);
sg('ow_day'.$i.'.civil_twilight_end', $sunInfo["civil_twilight_end"]);
}
$i++;
}
runScript(gg('ow_setting.updScript'));
}