Страница 10 из 22

Re: Модуль "Погода от Яндекс"

Добавлено: Вс мар 13, 2016 11:29 am
Smolalex
ipz писал(а):Погода уже несколько дней глючит. Вчера перестала совсем обновляться, в 16:00.

Чтобы не обнулялись показатели при сбое у себя поставил в WeatherFromYandex строчки после

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

$xml = simplexml_load_file($data_file); // раскладываем xml на массив
проверка

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

if($xml === false ) { // Проверить можно также !is_object( $xml ) или !$xml
     return; 
}
При этом не сбрасываются время заката/рассвета и др. если данные по к.л. причинам не получены (отвалился интернет, глючит Яндекс)
Для этого я использую расчётное время заката/рассвета.
SPOILERSPOILER_SHOW
include_once(ROOT.'scripts/suncalc.php');
$sun = new sun($this->getProperty("Latitude"), $this->getProperty("Longitude"),$this->getProperty("Timezone"));
$my_sunrise = $sun->sunrise();
$this->setProperty("SunRiseC",$my_sunrise);
$this->setProperty("SunRiseCN",date("G:i",$my_sunrise));
$my_sunset = $sun->sunset();
$this->setProperty("SunSetC",$my_sunset);
$this->setProperty("SunSetCN",date("G:i",$my_sunset));
SPOILERSPOILER_SHOW
<?php

class sun
{
var $latitude; #szerokosc geograficzna
var $longitude; #dlugosc geograficzna
var $timezone; #strefa czasowa
function sun ($latitude, $longitude, $timezone)
{
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->timezone = $timezone;
$this->yday = date("z");
$this->mon = date("n");
$this->mday = date("j");
$this->year = date("Y");
#---------------------
$this->DST=$this->is_daylight_time(date("U"));
if ($this->DST)
{
$this->timezone = ($this->timezone + 1);
}
if ($this->timezone == "13")
{
$this->timezone = "-11";
}
#---------------------
$this->A = 1.5708;
$this->B = 3.14159;
$this->C = 4.71239;
$this->D = 6.28319;
$this->E = 0.0174533 * $this->latitude;
$this->F = 0.0174533 * $this->longitude;
$this->G = 0.261799 * $this->timezone;
#---------------------
# For astronomical twilight, use
#$this->R = -.309017;
# For nautical twilight, use
#$this->R = -.207912;
# For civil twilight, use
#$this->R = -.104528;
# For sunrise or sunset, use
$this->R = -.0145439;
#---------------------

}
function is_daylight_time($time)
{
list($dom, $dow, $month, $hour, $min) = explode(":", date("d:w:m:H:i", $time));
if ($month > 4 && $month < 10)
{
$this->retval = 1; # May thru September
}
elseif ($month == 4 && $dom > 7)
{
$this->retval = 1; # After first week in April
}
elseif ($month == 4 && $dom <= 7 && $dow == 0 && $hour >= 2)
{
$this->retval = 1; # After 2am on first Sunday ($dow=0) in April
}
elseif ($month == 4 && $dom <= 7 && $dow != 0 && ($dom-$dow > 0))
{
$this->retval = 1; # After Sunday of first week in April
}
elseif ($month == 10 && $dom < 25)
{
$this->retval = 1; # Before last week of October
}
elseif ($month == 10 && $dom >= 25 && $dow == 0 && $hour < 2)
{
$this->retval = 1; # Before 2am on last Sunday in October
}
elseif ($month == 10 && $dom >= 25 && $dow != 0 && ($dom-24-$dow < 1) )
{
$this->retval = 1; # Before Sunday of last week in October
}
else
{
$this->retval = 0;
}



return $this->retval;
}
function sunrise()
{
$J = $this->A;
$K = $this->yday + (($J - $this->F) / $this->D);
$L = ($K * .017202) - .0574039; # Solar Mean Anomoly
$M = $L + .0334405 * sin($L); # Solar True Longitude
$M += 4.93289 + (3.49066E-04) * sin(2 * $L);
if ($this->D == 0)
{
echo "Trying to normalize with zero offset..."; exit;
}
while ($M < 0)
{
$M = ($M + $this->D);
}
while ($M >= $this->D)
{
$M = ($M - $this->D);
}
if (($M / $this->A) - intval($M / $this->A) == 0)
{
$M += 4.84814E-06;
}
$P = sin($M) / cos($M); # Solar Right Ascension
$P = atan2(.91746 * $P, 1);
# Quadrant Adjustment
if ($M > $this->C)
{
$P += $this->D;
}
else
{
if ($M > $this->A)
{
$P += $this->B;
}
}

$Q = .39782 * sin($M); # Solar Declination
$Q = $Q / sqrt(-$Q * $Q + 1); # This is how the original author wrote it!
$Q = atan2($Q, 1);
$S = $this->R - (sin($Q) * sin($this->E));
$S = $S / (cos($Q) * cos($this->E));
if (abs($S) > 1)
{
echo 'none';
} # Null phenomenon
$S = $S / sqrt(-$S * $S + 1);
$S = $this->A - atan2($S, 1);
$S = $this->D - $S ;
$T = $S + $P - 0.0172028 * $K - 1.73364; # Local apparent time
$U = $T - $this->F; # Universal timer
$V = $U + $this->G; # Wall clock time
# Quadrant Determination
if ($this->D == 0)
{
echo "Trying to normalize with zero offset..."; exit;
}
while ($V < 0)
{
$V = ($V + $this->D);
}
while ($V >= $this->D)
{
$V = ($V - $this->D);
}
$V = $V * 3.81972;
$hour = intval($V);
$min = intval((($V - $hour) * 60) + 0.5);
// return date( "G:i ", mktime($hour,$min,0,$this->mon,$this->mday,$this->year) - 1800 );
return mktime($hour,$min,0,$this->mon,$this->mday,$this->year) ;
}
function sunset()
{
$J = $this->C;
$K = $this->yday + (($J - $this->F) / $this->D);
$L = ($K * .017202) - .0574039; # Solar Mean Anomoly
$M = $L + .0334405 * sin($L); # Solar True Longitude
$M += 4.93289 + (3.49066E-04) * sin(2 * $L);
if ($this->D == 0)
{
echo "Trying to normalize with zero offset..."; exit;
}
while ($M < 0)
{
$M = ($M + $this->D);
}
while ($M >= $this->D)
{
$M = ($M - $this->D);
}
if (($M / $this->A) - intval($M / $this->A) == 0)
{
$M += 4.84814E-06;
}
$P = sin($M) / cos($M); # Solar Right Ascension
$P = atan2(.91746 * $P, 1);
# Quadrant Adjustment
if ($M > $this->C)
{
$P += $this->D;
}
else
{
if ($M > $this->A)
{
$P += $this->B;
}
}

$Q = .39782 * sin($M); # Solar Declination
$Q = $Q / sqrt(-$Q * $Q + 1); # This is how the original author wrote it!
$Q = atan2($Q, 1);
$S = $this->R - (sin($Q) * sin($this->E));
$S = $S / (cos($Q) * cos($this->E));
if (abs($S) > 1)
{
echo 'none';
} # Null phenomenon
$S = $S / sqrt(-$S * $S + 1);
$S = $this->A - atan2($S, 1);
#$S = $this->D - $S ;
$T = $S + $P - 0.0172028 * $K - 1.73364; # Local apparent time
$U = $T - $this->F; # Universal timer
$V = $U + $this->G; # Wall clock time
# Quadrant Determination
if ($this->D == 0)
{
echo "Trying to normalize with zero offset..."; exit;
}
while ($V < 0)
{
$V = ($V + $this->D);
}
while ($V >= $this->D)
{
$V = ($V - $this->D);
}
$V = $V * 3.81972;
$hour = intval($V);
$min = intval((($V - $hour) * 60) + 0.5);
//return date( "G:i ", mktime($hour,$min,0,$this->mon,$this->mday,$this->year) + 1800 );
return mktime($hour,$min,0,$this->mon,$this->mday,$this->year) ;
}

}

//$ext_light = show_list($keys_id, "#key_pio#", "", 1, "key_label='ext_light'", 1);

?>

Re: Модуль "Погода от Яндекс"

Добавлено: Вс мар 13, 2016 11:37 am
Smolalex
У класса POGODA имеются объекты города, например MOSCOW ....
свойства объектов
Latitude,Longitude,Timezone
в первом спойлере метод класса POGODA

Re: Модуль "Погода от Яндекс"

Добавлено: Вс мар 13, 2016 12:47 pm
DiArt
У яндекса сервера похоже перегружены.
Если обновить страницу нажав несколько раз - то показывает
https://export.yandex.ru/weather-ng/forecasts/[id].xml
Необходимо просто сделать проверку в сценарии - если xml отдает false, то выполнить сценарий через 5 секунд.

Re: Модуль "Погода от Яндекс"

Добавлено: Ср мар 16, 2016 7:04 am
nick7zmail
DiArt писал(а): Необходимо просто сделать проверку в сценарии - если xml отдает false, то выполнить сценарий через 5 секунд.
Как бы зацикливания не получилось в случае отсутствия инета))... Кол-во попыток ограничить надо.

Re: Модуль "Погода от Яндекс"

Добавлено: Ср мар 16, 2016 7:29 am
Amarok
nick7zmail писал(а):Как бы зацикливания не получилось в случае отсутствия инета))... Кол-во попыток ограничить надо.

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

if (isOnline('Internet')) {
...
}
 

Re: Модуль "Погода от Яндекс"

Добавлено: Ср мар 16, 2016 9:59 am
skysilver
nick7zmail писал(а):
DiArt писал(а): Необходимо просто сделать проверку в сценарии - если xml отдает false, то выполнить сценарий через 5 секунд.
Как бы зацикливания не получилось в случае отсутствия инета))... Кол-во попыток ограничить надо.
Все уже давно реализовано, правда не в модуле а в сценарии. ;)

Вот тут я предлагал свое решение http://majordomo.smartliving.ru/forum/v ... =40#p21296
  • обработка ошибок при запросе XML
  • таймаут ожидания при запросе XML
  • несколько попыток запроса XML
  • проверка на существование нужных полей в XML
  • запись в лог

Re: Модуль "Погода от Яндекс"

Добавлено: Пн мар 21, 2016 9:11 pm
zarro
Погода обновляется нестабильно. Картинки не отображаются.

Re: Модуль "Погода от Яндекс"

Добавлено: Вт мар 22, 2016 1:12 pm
Aleks130699
Привет всем.У меня такая проблема , не обновляется яндекс погода уже около недели, причем не модулю не код не может получить данные.Выдает такую ошибку
SPOILERSPOILER_SHOW
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://export.yandex.ru/weather-ng/forecasts/29570.xml" in C:\_majordomo\htdocs\modules\app_yaweather\app_yaweather.class.php on line 246

Warning: Invalid argument supplied for foreach() in C:\_majordomo\htdocs\modules\app_yaweather\app_yaweather.class.php on line 280

Re: Модуль "Погода от Яндекс"

Добавлено: Вт мар 22, 2016 2:44 pm
chuk3
Aleks130699 писал(а):Привет всем.У меня такая проблема , не обновляется яндекс погода уже около недели, причем не модулю не код не может получить данные.Выдает такую ошибку
SPOILERSPOILER_SHOW
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://export.yandex.ru/weather-ng/forecasts/29570.xml" in C:\_majordomo\htdocs\modules\app_yaweather\app_yaweather.class.php on line 246

Warning: Invalid argument supplied for foreach() in C:\_majordomo\htdocs\modules\app_yaweather\app_yaweather.class.php on line 280
Яндекс перешел на HTTPS, поэтому адрес нужно сменить на https://export.yandex.ru/weather-ng/forecasts/29570.xml.

Re: Модуль "Погода от Яндекс"

Добавлено: Ср мар 23, 2016 8:02 pm
Aleks130699
chuk3 писал(а): Яндекс перешел на HTTPS, поэтому адрес нужно сменить на https://export.yandex.ru/weather-ng/forecasts/29570.xml.
Не помогло, и в браузере эта страница не открывается.