Re: Элемент сцены Погода
Добавлено: Пн мар 16, 2015 1:09 pm
блин
file_exists
невнимательность )
file_exists
невнимательность )
А где в SVG брать?Bagir писал(а):Еще можно их в svg скрасть и сразу в коде элемента рисовать.
Код: Выделить всё
<svg enable-background="new 0 0 30 30" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg"><path d="M5.6 22c-1.8 0-3.3-1.6-3.3-3.4 0-1.8 1.5-3.3 3.3-3.3h.2c.6-1.9 2.2-3.2 4.2-3.2.1 0 .2 0 .4.1.9-2.6 3.4-4.6 6.3-4.6 3.3 0 6.1 2.4 6.6 5.6.5-.1.9-.2 1.3-.2 2.5 0 4.5 2 4.5 4.5s-2 4.5-4.5 4.5h-19zm17.73-7c-.767.343-.96.367-1.16.267-.2-.1-.215-.267-.4-1.067-.452-2.934-2.27-4.8-4.97-4.8-2.6 0-4.8 2.1-4.8 4.6 0 .4-.1.5-.5.2-.4-.2-.9-.4-1.4-.4-1.4 0-2.6 1.1-2.7 2.8 0 .4.1.8 0 .9-.1.1-.3-.1-.8-.3-.517-.2-.8-.2-1-.2-.8 0-1.5.7-1.5 1.5S4.8 20 5.6 20h19c1.4 0 2.6-1.2 2.6-2.6 0-1.4-1.1-2.6-2.6-2.6-.33 0-.882.027-1.27.2z" fill="#006ED4" fill-rule="evenodd"/></svg>
Код: Выделить всё
<?php
$col = 3; // кол-во дней (до 10, увеличивается время выдачи)
$data_file = 'http://weather.yandex.ru/static/cities.xml';
$xml = simplexml_load_file($data_file);
foreach ($xml->country as $key => $value) {
foreach ($value->city as $key1 => $value1):
$out = getWeather($value1["id"], $col);
foreach ($out as $day):
foreach ($day['weather'] as $weather):
$types[(string)$weather['weather_type']] = (string)$weather['image'];
$images[(string)$weather['image']] = (string)$weather['weather_type'];
endforeach;
endforeach;
endforeach;
}
foreach($images as $img=>$type):
echo '<img src="http://yandex.st/weather/1.2.61/i/icons/48x48/'.$img.'.png" width="48" height="48" /> -'. $type.'<br />';
$urlImage = 'http://yandex.st/weather/1.2.61/i/icons/48x48/'.$img.'.png';
if (!file_exists($img.'.png')) {
file_put_contents($img.'.png', file_get_contents($urlImage));
}
endforeach;
function getWeather($city, $col = 10) {
$data_file = 'http://export.yandex.ru/weather-ng/forecasts/'.$city.'.xml';
$xml = simplexml_load_file($data_file);
$out = array();
$counter = 0 ;
if($xml->day):
foreach($xml->day as $day):
if($counter == $col) break;
for ($i=0;$i<=3;$i++) {
$out[$counter]['weather'][$i]['image'] = $day->day_part[$i]->{'image-v3'}; // тут задаем нужное поле файла XML
$out[$counter]['weather'][$i]['weather_type'] = $day->day_part[$i]->weather_type;
}
$counter++ ;
endforeach;
endif;
return $out ;
}
?>