Неполадки со скриптом php
Цитата: moskit от 28.04.2016, 13:26Здравствуйте, имеется скрипт парсер погоды от яндекса:
С недавнего времени он работать перестал, вероятно яндекс погода заблочило мой айпи хостинга ... не могу понять почему
Возможно версия php на хостинге например изменилась..
Скрипт тут http://ideone.com/oaizUe
<?php
$city_id = 28666; //id гоÑ
€Ð¾Ð´
а, впÐ
¸ÑÐ°Ñ
;‚ÑŒ свÐ
¾Ð¹, моÐ
¶Ð½Ð¾ узн
;атÑ
0; туÑ
‚ https://p...content-available-to-author-only..
.x.ru/static/cities.xml - пар
;аме
09;‚Ñ€ city id=
$cache_lifetime = 7200; //вр
8;µÐ¼Ñ кэÑ
ˆÐ° фай
;ла в сек
;унÐ
;´Ð°Ñ…, 3600=1 час
;
$cache_file = 'weather_'.$city_id.'.xml'; // врÐ
µÐ¼ÐµÐ
9;ны
8;¹ фай
;л-кÑ
41;шfunction loadxmlyansex($city_id)
{
$url = 'http://e...content-available-to-author-on
ly...x.ru/weather-ng/forecasts/'.$city_id.'
;.xml';
$userAgent = 'Googlebot/2.1 (+http://www.google.com/bot.html)'
;
$xml = 'weather_'.$city_id.'.xml';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$output = curl_exec($ch);
$fh = fopen($xml, 'w');
fwrite($fh, $output);
fclose($fh);
}if ( file_exists($cache_file) ) {
$cache_modified = time() - @filemtime($cache_file);
if ( $cache_modified > $cache_lifetime ){
//обÐ
89;ов
08;»ÑÐµÐ&
#188; фай
;л поÐ
³Ð¾Ð´
ы, есл
8;¸ врÐ
µÐ¼Ñ фай
;ла кэÑ
ˆÐ° усÑ
‚арÐ
;µÐ»Ð¾
loadxmlyansex($city_id);
}
}
else {
//есл&#
208;¸ нет
; фай
;ла поÐ
³Ð¾Ð´
Ñ‹ воÐ
¾Ð±Ñ‰Ð
;µ, зак
8;°Ñ‡Ð¸
08;²Ð°ÐµÐ&
#188; его
;
loadxmlyansex($city_id);
}
?>
<?php
if(file_exists($cache_file)):
$data = simplexml_load_file($cache_file); ?>
<style type="text/css">
.weather .date{font-size:13px;font-weight:700;paddi
ng-bottom:5px;text-transform:uppercase;bor
der-bottom:1px solid #d5d5d5;margin-top:10px;}
.weather .item{background-color:#DAD9D5;padding:15p
x;font-family:Georgia;margin-bottom:20px;}.weather .item table{border:0;width:100%;}
.weather .item table td{padding-bottom:15px;width:20%;vertical-
align:baseline;padding-right:5px;}
.weather .item .day-part td{font-size:18px;}
.weather .item .day-temp td{font-size:30px;}
.weather .item .day-temp td img{margin-left:5px;}
.weather .item .day-param td{font-size:12px;}
.weather .item .day-param td p{padding-bottom:3px;}
.weather .days{margin-top:35px;border:0;width:1
00%;}
.weather .days td{width:50%;padding-bottom:35px;}
.weather .days a{font-family:Georgia;font-size:18px;text-
decoration:underline;font-weight:700;}.tabs input[type=radio] {
position: absolute;
top: -9999px;
left: -9999px;
}
.tabs {
width: 700px;
float: right;
list-style: none;
position: relative;
padding: 0;
font-family: "Georgia";
}
.tabs li{
float: left;
}
.tabs label {
display: block;
padding: 10px 8px;
border-radius: 2px 2px 0 0;
color: #000;
font-size: 18px;
font-weight: normal;
font-family: 'Lily Script One', helveti;
background: rgba(255,255,255,0.2);
cursor: pointer;
position: relative;
top: 3px;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.tabs label:hover {
background: rgba(255,255,255,0.5);
top: 0;
}
[id^=tab]:checked + label {
background: rgba(0,153,204,1);
color: white;
}
[id^=tab]:checked ~ [id^=tab-content] {
display: block;
}
.tab-content{
z-index: 2;
display: none;
text-align: left;
width: 100%;
font-size: 20px;
line-height: 140%;
padding-top: 10px;
background: rgba(0,153,204,1);
padding: 15px;
color: white;
position: absolute;
top: 53px;
left: 0;
box-sizing: border-box;
-webkit-animation-duration: 0.5s;
-o-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
animation-duration: 0.5s;
}</style><div class="weather"><ul class="tabs"><?php
foreach($data->day as $day):?>
<li><?php $s6=$s6+1;?><input type="radio"
<?php if($s6==1) echo "checked";
else
echo "";?> name="tabs" id="tab<?php echo $s1=$s1+1;?>">
<label for="tab<?php echo $s2=$s2+1;?>"><div class="date"><?php echo getDayDate($day['date']);?
></div></label>
<div id="tab-content<?php echo $s3=$s3+1;?>" class="tab-content animated fadeIn">
<div class="item"><table><tr class="day-part"><td>Ð
;£Ñ‚Ñ€
;ом</td&
#62;<td>ДÐ&
;#189;ем</td>
<td>Ве
09;‡ÐµÑ€&#
208;¾Ð¼</td>
0;td>Но&
amp;#209;‡ÑŒÑ&
amp;#142;</td>
</tr><tr class="day-temp"><?php for($i = 0;$i < 4;$i++): // т.к. нам
; не нуÐ
¶Ð½Ñ‹ дан
;ныÐ
;µ day_short и night_short, мы осÑ
‚анÐ
;°Ð²Ð»Ð
84;вае&
#208;¼ прÐ
¾Ñ…о
д на 4
$img = $day->day_part[$i]->{'image-v3
'};?><td><?php echo getTempSign($day->day_part[$i]-
2;{'temperature-data'}->avg);?>
; °C <img src="pogoda/<?php echo $img;?>.png" width="48" height="48" /></td><?php endfor;?>
</tr><tr class="day-param"><?php for($i = 0;$i < 4;$i++): // т.к. нам
; не нуÐ
¶Ð½Ñ‹ дан
;ныÐ
;µ day_short и night_short, мы осÑ
‚анÐ
;°Ð²Ð»Ð
84;вае&
#208;¼ прÐ
¾Ñ…о
д на 4?>
<td><p><strong><?php echo $day->day_part[$i]->weather_type;?
></strong></p><p>&
#208;²ÐµÑ‚&
;#208;µÑ€: <?php echo getWindDirection($day->day_part[$i]
;->wind_direction).' '.$day->day_part[$i]->wind_spe
ed;?> м/с</p&#
62;
<p>вл
8;°Ð¶Ð½Ð&#
190;ст&#
209;Œ: <?php echo $day->day_part[$i]->humidity;?>
;%</p><p>д&
#208;°Ð²Ð»Ðµ&a
mp;#208;½Ð¸Ðµ&
#58; <?php echo $day->day_part[$i]->pressure;?>
; мм рт. ст.</p&#
62;
</td><?php endfor;?></tr></table></di
v></div></li><?php
endforeach;?>
</ul></div>
<?php
endif;
// поÐ
»ÑƒÑ‡Ð
;°ÐµÐ¼ лок
;али
08;·Ð¾Ð²&#
208;°Ð½Ð½&
#209;ƒÑŽ Ð´Ð°Ñ‚
;у
function getDayDate($date)
{
$date = strtotime($date);
$months = array('','/01','/02',&
#39;/03','/04','/05','/06&
#39;,'/07','/08','/09',
9;/10','/11','/12');
$days = array('Ð’Ð&
#161;','ПÐ&
;#157;', 'ВТ'
, 'СР', 'ЧТ', 'ПТ'
, 'СБ'
);
return $days[date('w', $date)].', '.(int)date('d',$date)
.' '.$months[date('n', $date)];
}
// поÐ
»ÑƒÑ‡Ð
;°ÐµÐ¼ зна
8;º тем
;пеÑ
8;атÑ
31;ры
function getTempSign($temp)
{
$temp = (int)$temp;
return $temp > 0 ? '+'.$temp : $temp;
}
// поÐ
»ÑƒÑ‡Ð
;°ÐµÐ¼ нап
;раÐ
8;лен&#
208;¸Ñ вет
;ра
function getWindDirection($wind)
{
$wind = (string)$wind;
$wind_direction = array('s'=>'↑ ÑŽ','n'=>'&a
mp;#8595; с','w'=>'&a
mp;#8594; з','e'=>'←
в','sw'=>'&
amp;#8599; юз','se'=
>'↖ юв','
;nw'=>'↘ сз','ne'=
>'↙ св')
;
return $wind_direction[$wind];
}
?>
Здравствуйте, имеется скрипт парсер погоды от яндекса:
С недавнего времени он работать перестал, вероятно яндекс погода заблочило мой айпи хостинга ... не могу понять почему
Возможно версия php на хостинге например изменилась..
Скрипт тут http://ideone.com/oaizUe
<?php
$city_id = 28666; //id гоÑ
€Ð¾Ð´
а, впÐ
¸ÑÐ°Ñ
;‚ÑŒ свÐ
¾Ð¹, моÐ
¶Ð½Ð¾ узн
;атÑ
0; туÑ
‚ https://p...content-available-to-author-only..
.x.ru/static/cities.xml - пар
;аме
09;‚Ñ€ city id=
$cache_lifetime = 7200; //вр
8;µÐ¼Ñ кэÑ
ˆÐ° фай
;ла в сек
;унÐ
;´Ð°Ñ…, 3600=1 час
;
$cache_file = 'weather_'.$city_id.'.xml'; // врÐ
µÐ¼ÐµÐ
9;ны
8;¹ фай
;л-кÑ
41;ш
function loadxmlyansex($city_id)
{
$url = 'http://e...content-available-to-author-on
ly...x.ru/weather-ng/forecasts/'.$city_id.'
;.xml';
$userAgent = 'Googlebot/2.1 (+http://www.google.com/bot.html)'
;
$xml = 'weather_'.$city_id.'.xml';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$output = curl_exec($ch);
$fh = fopen($xml, 'w');
fwrite($fh, $output);
fclose($fh);
}
if ( file_exists($cache_file) ) {
$cache_modified = time() - @filemtime($cache_file);
if ( $cache_modified > $cache_lifetime )
{
//обÐ
89;ов
08;»ÑÐµÐ&
#188; фай
;л поÐ
³Ð¾Ð´
ы, есл
8;¸ врÐ
µÐ¼Ñ фай
;ла кэÑ
ˆÐ° усÑ
‚арÐ
;µÐ»Ð¾
loadxmlyansex($city_id);
}
}
else {
//есл&#
208;¸ нет
; фай
;ла поÐ
³Ð¾Ð´
Ñ‹ воÐ
¾Ð±Ñ‰Ð
;µ, зак
8;°Ñ‡Ð¸
08;²Ð°ÐµÐ&
#188; его
;
loadxmlyansex($city_id);
}
?>
<?php
if(file_exists($cache_file)):
$data = simplexml_load_file($cache_file); ?>
<style type="text/css">
.weather .date{font-size:13px;font-weight:700;paddi
ng-bottom:5px;text-transform:uppercase;bor
der-bottom:1px solid #d5d5d5;margin-top:10px;}
.weather .item{background-color:#DAD9D5;padding:15p
x;font-family:Georgia;margin-bottom:20px;}
.weather .item table{border:0;width:100%;}
.weather .item table td{padding-bottom:15px;width:20%;vertical-
align:baseline;padding-right:5px;}
.weather .item .day-part td{font-size:18px;}
.weather .item .day-temp td{font-size:30px;}
.weather .item .day-temp td img{margin-left:5px;}
.weather .item .day-param td{font-size:12px;}
.weather .item .day-param td p{padding-bottom:3px;}
.weather .days{margin-top:35px;border:0;width:1
00%;}
.weather .days td{width:50%;padding-bottom:35px;}
.weather .days a{font-family:Georgia;font-size:18px;text-
decoration:underline;font-weight:700;}
.tabs input[type=radio] {
position: absolute;
top: -9999px;
left: -9999px;
}
.tabs {
width: 700px;
float: right;
list-style: none;
position: relative;
padding: 0;
font-family: "Georgia";
}
.tabs li{
float: left;
}
.tabs label {
display: block;
padding: 10px 8px;
border-radius: 2px 2px 0 0;
color: #000;
font-size: 18px;
font-weight: normal;
font-family: 'Lily Script One', helveti;
background: rgba(255,255,255,0.2);
cursor: pointer;
position: relative;
top: 3px;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.tabs label:hover {
background: rgba(255,255,255,0.5);
top: 0;
}
[id^=tab]:checked + label {
background: rgba(0,153,204,1);
color: white;
}
[id^=tab]:checked ~ [id^=tab-content] {
display: block;
}
.tab-content{
z-index: 2;
display: none;
text-align: left;
width: 100%;
font-size: 20px;
line-height: 140%;
padding-top: 10px;
background: rgba(0,153,204,1);
padding: 15px;
color: white;
position: absolute;
top: 53px;
left: 0;
box-sizing: border-box;
-webkit-animation-duration: 0.5s;
-o-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
animation-duration: 0.5s;
}</style><div class="weather"><ul class="tabs"><?php
foreach($data->day as $day):?>
<li><?php $s6=$s6+1;?><input type="radio"
<?php if($s6==1) echo "checked";
else
echo "";?> name="tabs" id="tab<?php echo $s1=$s1+1;?>">
<label for="tab<?php echo $s2=$s2+1;?>"><div class="date"><?php echo getDayDate($day['date']);?
></div></label>
<div id="tab-content<?php echo $s3=$s3+1;?>" class="tab-content animated fadeIn">
<div class="item"><table><tr class="day-part"><td>Ð
;£Ñ‚Ñ€
;ом</td&
#62;<td>ДÐ&
;#189;ем</td>
<td>Ве
09;‡ÐµÑ€&#
208;¾Ð¼</td>
0;td>Но&
amp;#209;‡ÑŒÑ&
amp;#142;</td>
</tr><tr class="day-temp"><?php for($i = 0;$i < 4;$i++): // т.к. нам
; не нуÐ
¶Ð½Ñ‹ дан
;ныÐ
;µ day_short и night_short, мы осÑ
‚анÐ
;°Ð²Ð»Ð
84;вае&
#208;¼ прÐ
¾Ñ…о
д на 4
$img = $day->day_part[$i]->{'image-v3
'};?><td><?php echo getTempSign($day->day_part[$i]-
2;{'temperature-data'}->avg);?>
; °C <img src="pogoda/<?php echo $img;?>.png" width="48" height="48" /></td><?php endfor;?>
</tr><tr class="day-param"><?php for($i = 0;$i < 4;$i++): // т.к. нам
; не нуÐ
¶Ð½Ñ‹ дан
;ныÐ
;µ day_short и night_short, мы осÑ
‚анÐ
;°Ð²Ð»Ð
84;вае&
#208;¼ прÐ
¾Ñ…о
д на 4?>
<td><p><strong><?php echo $day->day_part[$i]->weather_type;?
></strong></p><p>&
#208;²ÐµÑ‚&
;#208;µÑ€: <?php echo getWindDirection($day->day_part[$i]
;->wind_direction).' '.$day->day_part[$i]->wind_spe
ed;?> м/с</p&#
62;
<p>вл
8;°Ð¶Ð½Ð&#
190;ст&#
209;Œ: <?php echo $day->day_part[$i]->humidity;?>
;%</p><p>д&
#208;°Ð²Ð»Ðµ&a
mp;#208;½Ð¸Ðµ&
#58; <?php echo $day->day_part[$i]->pressure;?>
; мм рт. ст.</p&#
62;
</td><?php endfor;?></tr></table></di
v></div></li><?php
endforeach;?>
</ul></div>
<?php
endif;
// поÐ
»ÑƒÑ‡Ð
;°ÐµÐ¼ лок
;али
08;·Ð¾Ð²&#
208;°Ð½Ð½&
#209;ƒÑŽ Ð´Ð°Ñ‚
;у
function getDayDate($date)
{
$date = strtotime($date);
$months = array('','/01','/02',&
#39;/03','/04','/05','/06&
#39;,'/07','/08','/09',
9;/10','/11','/12');
$days = array('Ð’Ð&
#161;','ПÐ&
;#157;', 'ВТ'
, 'СР', 'ЧТ', 'ПТ'
, 'СБ'
);
return $days[date('w', $date)].', '.(int)date('d',$date)
.' '.$months[date('n', $date)];
}
// поÐ
»ÑƒÑ‡Ð
;°ÐµÐ¼ зна
8;º тем
;пеÑ
8;атÑ
31;ры
function getTempSign($temp)
{
$temp = (int)$temp;
return $temp > 0 ? '+'.$temp : $temp;
}
// поÐ
»ÑƒÑ‡Ð
;°ÐµÐ¼ нап
;раÐ
8;лен&#
208;¸Ñ вет
;ра
function getWindDirection($wind)
{
$wind = (string)$wind;
$wind_direction = array('s'=>'↑ ÑŽ','n'=>'&a
mp;#8595; с','w'=>'&a
mp;#8594; з','e'=>'←
в','sw'=>'&
amp;#8599; юз','se'=
>'↖ юв','
;nw'=>'↘ сз','ne'=
>'↙ св')
;
return $wind_direction[$wind];
}
?>
Цитата: moskit от 29.04.2016, 17:48Цитата: BeerManчто за адрес такой $url в функции loadxmlyansex ?
есть права чтобы создать фаил $cache_file ?Хз хз
вот отсюда скрипт брал
Ссылка
есть права чтобы создать фаил $cache_file ?
Хз хз
вот отсюда скрипт брал
Ссылка
