запускать можно раз в час, можно скрипт разделить для текущего дня и для прогноза и прогноз запускать реже.
Код: Выделить всё
// код для рег выражений https://tools.icoder.uz/regex-tester.php
// сайт, регулярное выражение, свойство в МД, номер переменной (если одна то не указывается)
function SaveToProp ($myurl, $myreg, $mdprop, $num = 1)
{
$isMatched = preg_match($myreg, $myurl, $matches);
$res = str_replace("+", "" , $matches[$num]);
$res = str_replace(".sun", "" , $res);
$res = str_replace(".moon", "" , $res);
sg($mdprop, $res);
echo $res."</br>";
}
function SaveToPropAll ($myurl, $myreg, $mdprop, $num = 1)
{
$isMatched = preg_match_all($myreg, $myurl, $matches);
$res = $matches[1][$num];
sg($mdprop, $res);
echo $res."</br>";
}
// текущая погода
$str = file_get_contents("http://m.gismeteo.com/weather/11938/current/"); //текущая погода
SaveToProp ($str, '/<td class="weather__temp"><span>(.+?)<\/span>/', "GismeteoCurrent.Temperature");
SaveToProp ($str, '/<td class="weather__desc">(.+?)<\/td>/', "GismeteoCurrent.description");
SaveToProp ($str, '/Feels: (.+?)<\/p>/', "GismeteoCurrent.Feels");
SaveToProp ($str, '/Pressure: (.+?) mmHg<\/p>/', "GismeteoCurrent.Pressure");
SaveToProp ($str, '/Humidity: (.+?) %<\/p>/', "GismeteoCurrent.Humidity");
SaveToProp ($str, '/Geomagnetic сonditions: (.+?) points<\/p>/', "GismeteoCurrent.Geomagnetic");
SaveToProp ($str, '/Wind: (.+?) m\/s,/', "GismeteoCurrent.Wind");
SaveToProp ($str, '/ m\/s, (.+?)<\/p>/', "GismeteoCurrent.Wind_direction");
SaveToProp ($str, '/Sunrise: (.+?)<\/p>/', "GismeteoCurrent.Sunrise");
SaveToProp ($str, '/Sunset: (.+?)<\/p>/', "GismeteoCurrent.Sunset");
SaveToProp ($str, '/Day length: (.+?)<\/p>/', "GismeteoCurrent.Day_length");
SaveToProp ($str, '/Moon: (.+?) %,/', "GismeteoCurrent.Moon");
SaveToProp ($str, '/ %, (.+?)<\/p>/', "GismeteoCurrent.Moon_type");
SaveToProp ($str, '/<div class="title">(.+?), (.+?) (.+?), (.+?)<\/div>/', "GismeteoCurrent.date_day", 2);
SaveToProp ($str, '/<div class="title">(.+?), (.+?) (.+?), (.+?)<\/div>/', "GismeteoCurrent.date_month", 3);
SaveToProp ($str, '/<div class="title">(.+?), (.+?) (.+?), (.+?)<\/div>/', "GismeteoCurrent.date_time", 4);
SaveToProp ($str, '/<td class="weather__icon"><img alt="" src="\/static\/images\/icons\/wap2\/(.+?)\.png" \/><\/td>/', "GismeteoCurrent.Image");
// функция для параметров погоды детально
function Detail($myurl, $param0, $param1, $param2) {
SaveToPropAll ($myurl, '/<div class="title">(.+?)<\/div>/', $param0 . "." . $param1 . "TimesofDay", $param2 + 1);
SaveToPropAll ($myurl, '/<td class="weather__temp"><span>(.+?)<\/span>/', $param0.".".$param1."Temperature", $param2);
SaveToPropAll ($myurl, '/<td class="weather__desc">(.+?)<\/td>/', $param0.".".$param1."Description", $param2);
SaveToPropAll ($myurl, '/Feels: (.+?)<\/p>/', $param0.".".$param1."Feels", $param2);
SaveToPropAll ($myurl, '/Pressure: (.+?) mmHg<\/p>/', $param0.".".$param1."Pressure", $param2);
SaveToPropAll ($myurl, '/Humidity: (.+?) %<\/p>/', $param0.".".$param1."Humidity", $param2);
SaveToPropAll ($myurl, '/Geomagnetic сonditions: (.+?) points<\/p>/', $param0.".".$param1."Geomagnetic", $param2);
}
$str = file_get_contents("http://m.gismeteo.com/weather/11938/detailday/"); //погода подробно на текущий день
Detail ($str, "GismeteoDetailday", "Night", 0 );
Detail ($str, "GismeteoDetailday", "Morning", 1 );
Detail ($str, "GismeteoDetailday", "Day", 2 );
Detail ($str, "GismeteoDetailday", "Evening", 3 );
$str = file_get_contents("http://m.gismeteo.com/weather/11938/detailday/1/"); //погода подробно на завтра
Detail ($str, "GismeteoDetailday1", "Night", 0 );
Detail ($str, "GismeteoDetailday1", "Morning", 1 );
Detail ($str, "GismeteoDetailday1", "Day", 2 );
Detail ($str, "GismeteoDetailday1", "Evening", 3 );
$str = file_get_contents("http://m.gismeteo.com/weather/11938/detailday/2/"); //погода подробно на послезавтра
Detail ($str, "GismeteoDetailday2", "Night", 0 );
Detail ($str, "GismeteoDetailday2", "Morning", 1 );
Detail ($str, "GismeteoDetailday2", "Day", 2 );
Detail ($str, "GismeteoDetailday2", "Evening", 3 );
$str = file_get_contents("http://m.gismeteo.com/weather/11938/detailday/3/"); //погода подробно через 2 дня
Detail ($str, "GismeteoDetailday3", "Night", 0 );
Detail ($str, "GismeteoDetailday3", "Morning", 1 );
Detail ($str, "GismeteoDetailday3", "Day", 2 );
Detail ($str, "GismeteoDetailday3", "Evening", 3 );