Страница 15 из 15

Re: Как погоду настроить

Добавлено: Вс мар 24, 2019 3:54 pm
nick7zmail
Зачем вам регулярки? У нас есть модуль яндекс погоды, который умеет вытягивать оттуда погоду...

Re: Как погоду настроить

Добавлено: Вс мар 24, 2019 4:04 pm
Amarok
nick7zmail писал(а): Чт июл 14, 2016 2:02 pm
Amarok писал(а):В общем у меня такой сценарий:
SPOILERSPOILER_SHOW

Код: Выделить всё

$url = "";
$xml = simplexml_load_file($url);
$city = "NTuraGismeteo";

$name = $xml->location['name']; if(gg($city.".name")!=$name){sg($city.".name",$name);}
$name_r = $xml->location['name_r']; if(gg($city.".name_r")!=$name_r){sg($city.".name_r",$name_r);}
$durm = $xml->location->day[0]['durm']; if(gg($city.".durm")!=$durm){sg($city.".durm",$durm);}
$tmin = $xml->location->day[0]['tmin']; if(gg($city.".tmin")!=$tmin){sg($city.".tmin",$tmin);}
$tmax = $xml->location->day[0]['tmax']; if(gg($city.".tmax")!=$tmax){sg($city.".tmax",$tmax);}
if($tmin>0){$tmin="+".$tmin;} if($tmax>0){$tmax="+".$tmax;}
$pmin = $xml->location->day[0]['pmin']; if(gg($city.".pmin")!=$pmin){sg($city.".pmin",$pmin);}
$pmax = $xml->location->day[0]['pmax']; if(gg($city.".pmax")!=$pmax){sg($city.".pmax",$pmax);}
$wsmin = $xml->location->day[0]['wsmin']; if(gg($city.".wsmin")!=$wsmin){sg($city.".wsmin",$wsmin);}
$wsmax = $xml->location->day[0]['wsmax']; if(gg($city.".wsmax")!=$wsmax){sg($city.".wsmax",$wsmax);}
$hummin = $xml->location->day[0]['hummin']; if(gg($city.".hummin")!=$hummin){sg($city.".hummin",$hummin);}
$hummax = $xml->location->day[0]['hummax']; if(gg($city.".hummax")!=$hummax){sg($city.".hummax",$hummax);}
$cl = $xml->location->day[0]['cl']; if(gg($city.".cl")!=$cl){sg($city.".cl",$cl);}
$pt = $xml->location->day[0]['pt']; if(gg($city.".pt")!=$pt){sg($city.".pt",$pt);}
$pr = $xml->location->day[0]['pr']; if(gg($city.".pr")!=$pr){sg($city.".pr",$pr);}
$ts = $xml->location->day[0]['ts']; if(gg($city.".ts")!=$ts){sg($city.".ts",$ts);}
$descr = $xml->location->day[0]['descr']; if(gg($city.".descr")!=$descr){sg($city.".descr",$descr);}
$grademax = $xml->location->day[0]['grademax']; if(gg($city.".grademax")!=$grademax){sg($city.".grademax",$grademax);}

$today = "Сегодня ".$name_r." ".$tmin."° — ".$tmax."°. ".$descr.". ";
//Сегодня утром
if ($xml->location->day[0]->forecast['tod'] == 1){
 $t = $xml->location->day[0]->forecast->values['t'];
 if($t>0){$t="+".$t;}
 $descr = $xml->location->day[0]->forecast->values['descr'];
 $today_morning = "Утром до ".$t."°. ".$descr.". ";
}

//Сегодня днем
if ($xml->location->day[0]->forecast['tod'] == 2){
 $t = $xml->location->day[0]->forecast->values['t'];
 if($t>0){$t="+".$t;}
 $descr = $xml->location->day[0]->forecast->values['descr'];
 $today_day = "Днём до ".$t."°. ".$descr.". ";
}

//Сегодня вечером
if ($xml->location->day[0]->forecast['tod'] == 3){
 $t = $xml->location->day[0]->forecast->values['t'];
 if($t>0){$t="+".$t;}
 $descr = $xml->location->day[0]->forecast->values['descr'];
 $today_evening = "Вечером до ".$t."°. ".$descr.". ";
}

//Сегодня ночью
if ($xml->location->day[1]->forecast['tod'] == 0){
 $t = $xml->location->day[1]->forecast->values['t'];
 if($t>0){$t="+".$t;}
 $descr = $xml->location->day[1]->forecast->values['descr'];
 $today_night = "Ночью до ".$t."°. ".$descr.".";
}

$forecast = $today.$today_morning.$today_day.$today_evening.$today_night;
if(gg($city.".forecast")!=$forecast){sg($city.".forecast",$forecast);}

//Завтра
$tmin = $xml->location->day[1]['tmin'];
$tmax = $xml->location->day[1]['tmax'];
$descr = $xml->location->day[1]['descr'];
if($tmin>0){$tmin="+".$tmin;}
if($tmax>0){$tmax="+".$tmax;}
$tomorrow = "Завтра "." ".$tmin."° — ".$tmax."°. ".$descr.". ";

//Завтра ночью
if ($xml->location->day[2]->forecast['tod'] == 0){
 $t = $xml->location->day[2]->forecast->values['t'];
 if($t>0){$t="+".$t;}
 $descr = $xml->location->day[2]->forecast->values['descr'];
 $tomorrow_night = "Завтра ночью до ".$t."°. ".$descr.".";
}

$forecastTomorrow = $tomorrow.$tomorrow_night;
if(gg($city.".forecastTomorrow")!=$forecastTomorrow){sg($city.".forecastTomorrow",$forecastTomorrow);}
Значение $url я получил после регистрации на сайте Gismeteo. Для этого надо написать письмо на [email protected] и попросить предоставить доступ к прогнозу погоды в xml-формате. Мне ответила любезная девушка, задала пару вопросов, выслала анкету (её надо заполнить) и - через некоторое время - у меня появился свой прогноз.

Приношу благодарности:
[*] сайту Gismeteo за предоставленный доступ к погодным данным на мой город
[*] менеджеру Gismeteo Валерии Сердюк за её терпение
[*] пользователю нашего форума m-malva за его код из которого я надёргал некоторые кусочки/идеи
Как скрипт? Работает? Я так понял - там только 4 раза в сутки погоду цеплять можно?
Пользуюсь модулем OpenWeather

Re: Как погоду настроить

Добавлено: Вс ноя 17, 2019 9:51 pm
Kashalex
Похожий вопрос уже был, но к сожалению я не смог применить указанный там ответ к решению моей проблемы
Со страницы ГисМетео
https://www.gismeteo.ru/weather-kashira-4373/
из кода
<div class="ii info_detail">
<div class="id_item title">Долгота дня
&mdash; 8 ч 21 мин</div>
<div class="id_item">Восход
&mdash; 8:01</div>
<div class="id_item">Заход
&mdash; 16:22</div>
</div>

Надо получить значение Восхода и Захода солнца.
Помогите.

Re: Как погоду настроить

Добавлено: Вс ноя 17, 2019 10:07 pm
Chainik
Kashalex писал(а): Вс ноя 17, 2019 9:51 pm ...
Надо получить значение Восхода и Захода солнца.
Помогите.
Вот правда не понимаю, зачем надо завязываться на внешние сервисы, если PHP умеет вычислять время восхода и заката Солнца.
Все делается в одну строчку (viewtopic.php?f=27&t=2215&start=41).
Вам надо только знать свои координаты. Ну и часы чтобы на компьютере правильную дату показывали.