Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 18.12.2022, 10:20
Новичок на форуме
Отправить личное сообщение для parshin Посмотреть профиль Найти все сообщения от parshin
 
Регистрация: 13.12.2022
Сообщений: 6

Погода от openweathermap
Добрый день
Есть код, показывающий текущую погоду от openweathermap
/* global axios, res */

function weather(){
    const sec = 1000;
    const min = 60 * sec;
    const hour = 60 * min;
    const delay = (0 * hour) + (1 * min) + (0 * sec);
    var d = new Date();
    var month_num = d.getMonth();
    var week_num = d.getDay();
    var day = d.getDate();
    var hours = d.getHours();
    var minutes = d.getMinutes();
    var seconds = d.getSeconds();
    month = new Array("января", "февраля", "марта", "апреля", "мая", "июня",
    		      "июля", "августа", "сентября", "октября", "ноября", "декабря");
    week = new Array("воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота");
    if (day <= 9) day = "0" + day;
    if (hours <= 9) hours = "0" + hours;
    if (minutes <= 9) minutes = "0" + minutes;
    if (seconds <= 9) seconds = "0" + seconds;
  
// API ключ
let apiKey = "45aef403d21cba00f8464647a9595250";
// Город погода которого нужна
let city = "Perm";
// Формируем url для GET запроса
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&lang=ru&units=metric&appid=${apiKey}`;
// Отправка GET запроса
axios.get(url).then(res => {
   // Вывод города
   document.querySelector('.city').innerHTML = res.data.name;
   // Вывод температуры
   document.querySelector('.temp').innerHTML = res.data.main.temp;
   document.querySelector('.f_l').innerHTML = res.data.main.feels_like;
   // Вывод давления
   document.querySelector('.pressure').innerHTML = res.data.main.pressure * 0.750063755419211;
   // Вывод скорости ветра
   document.querySelector('.w_d').innerHTML = res.data.wind.deg;
   document.querySelector('.wind').innerHTML = res.data.wind.speed;
   // Вывод влажности
   document.querySelector('.humidity').innerHTML = res.data.main.humidity;
   // Вывод восхода и заката солнца
   document.querySelector('.sunrise').innerHTML = res.data.sys.sunrise;
   document.querySelector('.sunset').innerHTML = res.data.sys.sunset;
   document.querySelector('.set_rise').innerHTML = res.data.sys.sunset - res.data.sys.sunrise;
});
    
    date_time = '<div class="weather" style="text-align: center;height: 252px;width: 350px;border-style: outset; border-width: 5px; background-color:#000000;">' +
                '<table width="100%" height="100%" cellspasing="0" cellpadding="0">' +
                '<tr><td nowrap style="width: 350px;height: 252px;background-size: cover;background-image: url(../formula1/images/fon0.gif)">' +
                    '<font style="font-size: 18pt;text-align: center;font-weight: bold" color="#00FFFF">' +
                        '<p style="margin-bottom: 10px;margin-top: 2px"><span class="city"></span></p>' +
                    '</font>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;text-align: center"><font style="font-size: 14pt; color: #FFFFFF">' + week[week_num] + 
                    '<br>' + day + ' ' + month[month_num] + ' ' + d.getFullYear() + '</font>' +
                    '<font face="LcdD" style="font-size: 14pt;font-style: normal; color: #FFFFFF"> ' + hours + ':' + minutes + '</font></p>' +
                    '<font style="font-size: 13pt;font-weight: bold" color="#FFFFFF">' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Погода: ' +
                    '<font color="#FFFF00"><span class="temp"></span>°C&nbsp;&nbsp;&nbsp;<font color="#FFFFFF"> По ощущению </font><span class="f_l"></span>°C</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Давление: <font color="#FFFF00"><span class="pressure"></span> мм рт. ст.</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Ветер: <font color="#FFFF00"><span class="w_d"></span>° <span class="wind"></span> м/с</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Влажность: <font color="#FFFF00"><span class="humidity"></span>%</font></p>' +
                    '<img src="../formula1/images/01d.png" width="48" height="48" alt="" align="left">' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Рассвет: <font color="#FFFF00"><span class="sunrise"></span><font color="#FFFFFF">&nbsp;&nbsp;&nbsp;Долгота дня </font><span class="set_rise"></span></font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Закат: <font color="#FFFF00"><span class="sunset"></span></font></p>' +
            '</font></td></tr></table></div>';
    if (document.layers) {
        document.layers.doc_time.document.write(date_time);
        document.layers.doc_time.document.close();
    }
    else document.getElementById("doc_time").innerHTML = date_time;
    setTimeout("weather()", delay);
}

Вопрос в том можно ли переделать так, чтобы данные присваивались переменным для их последующей обработки? Заранее благодарен.
Ответить с цитированием
  #2 (permalink)  
Старый 20.12.2022, 01:24
Новичок на форуме
Отправить личное сообщение для parshin Посмотреть профиль Найти все сообщения от parshin
 
Регистрация: 13.12.2022
Сообщений: 6

Есть идеально работающий php скрипт
<?php
    $city2_id="Perm"; // id города openweather.org
    $data_file2="http://api.openweathermap.org/data/2.5/weather?q=$city2_id&mode=xml&lang=ru&units=metric&appid=45aef403d21cba00f8464647a9595250"; // адрес xml файла
    $data_file2 = file_get_contents($data_file2,0); //получаем данные о погоде из xml файла
    $xml2 = new SimplexmlElement($data_file2); //помещаем данные в массив
    $city2= $xml2->city[name];//забиваем необходимые данные в переменные
    $temperature = $xml2->temperature[value];
    $feels_like = $xml2->feels_like[value];
    $weather_id = $xml2->weather[number];
    $weather_icon = $xml2->weather[icon];
    $weather_type = $xml2->weather[value];
    $pressure = $xml2->pressure[value];
    $humidity = $xml2->humidity[value];
    $sunrise = $xml2->city->sun[rise];
    $sunset = $xml2->city->sun[set];
    $windspeed = $xml2->wind->speed[value];
    $windcode = $xml2->wind->direction[code];
    $visibility = $xml2->visibility[value];
    if ($temperature > 0) {$temperature = '+'.$temperature;}
    $pressure = round($pressure * 0.750063755419211);
    $temperature = round($temperature);
    $feels_like = round($feels_like);
    date_default_timezone_set('Etc/GMT-5');
    $deff = strtotime($sunset) - strtotime($sunrise);
    $h_deff = floor($deff / 3600);
    $m_deff = floor(($deff - $h_deff * 3600) / 60);
    if ($pg == 0) $w_url = "weather/images/";
    if ($pg == 1) $w_url ="images/";
    if ($h_deff < 10) {$h_deff = '0'.$h_deff;}
    if ($m_deff < 10) {$m_deff = '0'.$m_deff;}
    $sunrise = date('H:i',strtotime("+5 hours", strtotime($sunrise)));
    $sunset = date('H:i',strtotime("+5 hours", strtotime($sunset)));
    $title2 = "Город: ".$city2."\n".$weather_type." ".$temperature."°C \nДавление: ".$pressure." мм рт. ст.\nВетер: ".$windcode." ".$windspeed." м/с \nВлажность: ".$humidity."%";
    $Day = date("d");
    $m = date("m");
    $Month = array (1 => "января",
                    2 => "февраля",
                    3 => "марта",
                    4 => "апреля",
                    5 => "мая",
                    6 => "июня",
                    7 => "июля",
                    8 => "августа",
                    9 => "сентября",
                   10 => "октября",
                   11 => "ноября",
                   12 => "декабря");
    $Year = date("Y");
    $w = date("w");
    $Week = array (0 => "воскресенье",
                   1 => "понедельник",
                   2 => "вторник",
                   3 => "среда",
                   4 => "четверг",
                   5 => "пятница",
                   6 => "суббота");
    $wind = array ( SW => "юго-западный",
                    SE => "юго-восточный",
                    NW => "северо-западный",
                    NE => "северо-восточный",
                    N => "северный",
                    S => "южный",
                    W => "западный",
                    E => "восточный",
                    WSW => "западно-юго-западный",
                    ESE => "восточно-юго-восточный",
                    SSW => "юго-юго-западный",
                    SSE => "юго-юго-восточный",
                    WNW => "западно-северо-западный",
                    ENE => "восточно-северо-восточный",
                    NNW => "северо-северо-западный",
                    NNE => "северо-северо-восточный");
?>

<div style="text-align: center;height: 290px;width: 350px;border-style: outset; border-width: 5px; background-color:#000000;">
    <table width='100%' height="100%" cellspasing='0' cellpadding='0'>
        <tr>
                <?php 
                echo '<td style="width: 100%;height: 100%;background-size: cover;background-image: url('.$w_url.'fon0.gif)">';
                ?>
                <font style="font-size: 18pt;text-align: center;font-weight: bold" color='#00FFFF'>
                    <p style="margin-bottom: 10px;margin-top: 2px"><?php echo $city2;?></p>
                </font>
                <font style="font-size: 14pt;color: #FFFFFF"><p style="margin-bottom: 2px;margin-top: 2px;text-align: center">
                <?php echo $Week[$w].'<br>'.$Day.' '.$Month[$m].' '.$Year.' <font face="LcdD">'.date("H:i").'</font><br>';?></font></p>
                <font style="font-size: 13pt;font-weight: bold" color='#FFFFFF'>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Погода: 
                    <?php
                        echo '<img width="32" height="32" src="'.$w_url.$weather_icon.'.png" alt="" title="'.$title2.'"> <font color="#FFFF00">'.$weather_type.'</font>';
                    ?>
                    <br>Температура: <font color='#FFFF00'><?php echo ($temperature."°C&nbsp;&nbsp;&nbsp;<font color='#FFFFFF'>По ощущению </font>".$feels_like."°C<br>");?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Давление: <font color='#FFFF00'><?php echo $pressure.' мм рт. ст.<br>';?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Ветер: <font color='#FFFF00'><?php echo $wind[trim($windcode)].' '.$windspeed.' м/с<br>';?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Влажность: <font color='#FFFF00'><?php echo $humidity.'%<br>';?></font></p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Видимость: <font color='#FFFF00'><?php echo $visibility.' м<br>';?></font></p>
                    <?php echo '<img src="'.$w_url.'01d.png" width="48" height="48" alt="" align="left">';?>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Рассвет: <font color='#FFFF00'><?php echo $sunrise.'&nbsp;&nbsp;&nbsp;';?></font>
                        Долгота дня: <font color='#FFFF00'><?php echo $h_deff.':'.$m_deff.'<br>';?></font>
                    </p>
                    <p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Закат: <font color='#FFFF00'><?php echo $sunset.'<br>';?></font></p>
                </font>
            </td>
        </tr>
    </table>
</div>

но он без автоматического обновления. Хотелось бы переделать его на javascript, но получается не совсем то, что нужно.
Ссылка http://pmm.h1n.ru/weather/ вверху php скрипт, внизу javascript.
Ответить с цитированием
  #3 (permalink)  
Старый 20.12.2022, 21:17
Новичок на форуме
Отправить личное сообщение для parshin Посмотреть профиль Найти все сообщения от parshin
 
Регистрация: 13.12.2022
Сообщений: 6

Практически все заработало, но появляется только после 1-го обновления через минуту и weather.icon; weather.description; почему то выводят undefined.
.
/* global w_out */

var city2, w_ico, w_des, temp, f_l, pressure, w_d, wind, humidity, visibility, sunrise, sunset, set_rise, t_z;
var data;
function getFile (fileName) {
    var request = new XMLHttpRequest();
    request.open('GET', fileName);
    request.onloadend = function() {
        parse(request.responseText);
    };
    request.timeout = 5000;
    request.send();
}

function parse(obj) {
    data = JSON.parse(obj);
    city2 = data.name;
    w_ico = data.weather.icon;
    w_des = data.weather.description;
    temp = data.main.temp;
    f_l = data.main.feels_like;
    pressure = data.main.pressure * 0.750063755419211;
    w_d = data.wind.deg;
    wind = data.wind.speed;
    humidity = data.main.humidity;
    visibility = data.visibility;
    sunrise = data.sys.sunrise;
    sunset = data.sys.sunset;
    set_rise = sunset - sunrise;
    t_z = data.timezone;
}

function weather(){
    const sec = 1000;
    const min = 60 * sec;
    const hour = 60 * min;
    const delay = (0 * hour) + (1 * min) + (0 * sec);
    var w_url = "weather/images/";
    if (pg === 1) w_url = "images/";
    var d = new Date();
    var month_num = d.getMonth();
    var week_num = d.getDay();
    var day = d.getDate();
    var hours = d.getHours();
    var minutes = d.getMinutes();
    var seconds = d.getSeconds();
    month = new Array("января", "февраля", "марта", "апреля", "мая", "июня",
    		      "июля", "августа", "сентября", "октября", "ноября", "декабря");
    week = new Array("воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота");
    if (day <= 9) day = "0" + day;
    if (hours <= 9) hours = "0" + hours;
    if (minutes <= 9) minutes = "0" + minutes;
    if (seconds <= 9) seconds = "0" + seconds;
  
let apiKey = "45aef403d21cba00f8464647a9595250";
let city = "Perm";
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&lang=ru&units=metric&appid=${apiKey}`;
    getFile(url);
    temp = Math.round(temp);
    f_l = Math.round(f_l);
    pressure = Math.round(pressure);
    h1 = Math.floor(set_rise / 3600);
    set_rise = set_rise - h1 * 3600;
    m1 = Math.floor(set_rise / 60);
    if (h1 < 10) h1 = "0" + h1;
    if (m1 < 10) m1 = "0" + m1;
    set_rise = h1 + ":" + m1;
    y1 = Math.floor(sunrise / (3600 * 24 * 365));
    sunrise = sunrise - y1 * (3600 * 24 * 365);
    d1 = Math.floor(sunrise /(3600 * 24));
    sunrise = sunrise - d1 *(3600 * 24) + t_z;
    h1 = Math.floor(sunrise / 3600);
    sunrise = sunrise - h1 * 3600;
    m1 = Math.floor(sunrise / 60);
    if (h1 < 10) h1 = "0" + h1;
    if (m1 < 10) m1 = "0" + m1;
    sunrise = h1 + ":" + m1;
    y1 = Math.floor(sunset / (3600 * 24 * 365));
    sunset = sunset - y1 * (3600 * 24 * 365);
    d1 = Math.floor(sunset /(3600 * 24));
    sunset = sunset - d1 *(3600 * 24) + t_z;
    h1 = Math.floor(sunset / 3600);
    sunset = sunset - h1 * 3600;
    m1 = Math.floor(sunset / 60);
    if (h1 < 10) h1 = "0" + h1;
    if (m1 < 10) m1 = "0" + m1;
    sunset = h1 + ":" + m1;
    if (((w_d >= 351) && (w_d <= 360)) || ((w_d >= 0) && (w_d <= 11))) w_d = "северный";
    if (((w_d >= 12) && (w_d <= 34))) w_d = "северо-северо-восточный";
    if (((w_d >= 35) && (w_d <= 56))) w_d = "северо-восточный";
    if (((w_d >= 57) && (w_d <= 80))) w_d = "восточно-северо-восточный";
    if (((w_d >= 81) && (w_d <= 102))) w_d = "восточный";
    if (((w_d >= 103) && (w_d <= 125))) w_d = "восточно-юго-восточный";
    if (((w_d >= 126) && (w_d <= 148))) w_d = "юго-восточный";
    if (((w_d >= 149) && (w_d <= 170))) w_d = "юго-юго-восточный";
    if (((w_d >= 171) && (w_d <= 193))) w_d = "южный";
    if (((w_d >= 194) && (w_d <= 215))) w_d = "юго-юго-западный";
    if (((w_d >= 216) && (w_d <= 238))) w_d = "юго-западный";
    if (((w_d >= 239) && (w_d <= 260))) w_d = "западно-юго-западный";
    if (((w_d >= 261) && (w_d <= 283))) w_d = "западный";
    if (((w_d >= 284) && (w_d <= 305))) w_d = "западно-северо-западный";
    if (((w_d >= 306) && (w_d <= 328))) w_d= "северо-западный";
    if (((w_d >= 329) && (w_d <= 350))) w_d = "северо-северо-западный";

    date_time = '<div class="weather" style="text-align: center;height: 290px;width: 350px;border-style: outset; border-width: 5px; background-color:#000000;">' +
                '<table width="100%" height="100%" cellspasing="0" cellpadding="0">' +
                '<tr><td nowrap style="width: 100%;height: 100%background-size: cover;background-image: url(' + w_url +'fon0.gif)">' +
                    '<font style="font-size: 18pt;text-align: center;font-weight: bold" color="#00FFFF">' +
                        '<p style="margin-bottom: 10px;margin-top: 2px">'+city2+'</p>' +
                    '</font>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;text-align: center"><font style="font-size: 14pt; color: #FFFFFF">' + week[week_num] + 
                    '<br>' + day + ' ' + month[month_num] + ' ' + d.getFullYear() + '</font>' +
                    '<font face="LcdD" style="font-size: 14pt;font-style: normal; color: #00FF66"> ' + hours + ':' + minutes + '</font></p>' +
                    '<font style="font-size: 13pt" color="#FFFFFF">' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Погода: ' +
                    '<img width="32" height="32" src="'+w_url+w_ico+'.png" alt=""><font color="#FFFF00"> '+w_des+'</font><br>' +
                    'Температура: <font color="#FFFF00">'+temp+'°C&nbsp;&nbsp;&nbsp;<font color="#FFFFFF"> По ощущению </font>'+f_l+'°C</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Давление: <font color="#FFFF00">'+pressure+' мм рт. ст.</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Ветер: <font color="#FFFF00">'+w_d+' '+wind+' м/с</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Влажность: <font color="#FFFF00">'+humidity+'%</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Видимость: <font color="#FFFF00">'+visibility+' м</font></p>' +
                    '<img src="' + w_url + '01d.png" width="48" height="48" alt="" align="left">' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Рассвет: <font color="#FFFF00">'+sunrise+'<font color="#FFFFFF">&nbsp;&nbsp;&nbsp;Долгота дня </font>'+set_rise+'</font></p>' +
                    '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Закат: <font color="#FFFF00">'+sunset+'</font></p>' +
            '</font></td></tr></table></div>';
    w_out.innerHTML = date_time;
    setTimeout(() => weather(), delay);
}

Последний раз редактировалось parshin, 20.12.2022 в 21:41.
Ответить с цитированием
  #4 (permalink)  
Старый 21.12.2022, 00:00
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

погода api openweathermap
Сообщение от parshin
weather.icon; weather.description; почему то выводят undefined.
.
data.weather это массив,
нужно указать индекс нужного элемента.
Сообщение от parshin
появляется только после 1-го обновления через минуту
нарушена логика, сначала идёт обработка данных, а потом запрос этих данных, для первого показа нечего обрабатывать.
- а надо, получили данные, затем их обработали.
<!DOCTYPE html>
<html>

<head>
    <title>Untitled</title>
    <meta charset="utf-8">
</head>

<body>
    <div id="w_out"></div>
    <script>
        /* global w_out */

        var city2, w_ico, w_des, temp, f_l, pressure, w_d, wind, humidity, visibility, sunrise, sunset, set_rise, t_z;
        var data;
        let apiKey = "45aef403d21cba00f8464647a9595250";
        let city = "Perm";
        let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&lang=ru&units=metric&appid=${apiKey}`;

        function getFile(fileName) {
            var request = new XMLHttpRequest();
            request.open('GET', fileName);
            request.onloadend = function() {
                parse(request.responseText);
                weather();
            };
            request.timeout = 5000;
            request.send();
        };

        function parse(obj) {
            data = JSON.parse(obj);
            city2 = data.name;
            w_ico = data.weather[0].icon;
            w_des = data.weather[0].description;
            temp = data.main.temp;
            f_l = data.main.feels_like;
            pressure = data.main.pressure * 0.750063755419211;
            w_d = data.wind.deg;
            wind = data.wind.speed;
            humidity = data.main.humidity;
            visibility = data.visibility;
            sunrise = data.sys.sunrise;
            sunset = data.sys.sunset;
            set_rise = sunset - sunrise;
            t_z = data.timezone;
        }

        function weather() {
            const sec = 1000;
            const min = 60 * sec;
            const hour = 60 * min;
            const delay = (0 * hour) + (1 * min) + (0 * sec);
            var w_url = "http://pmm.h1n.ru/weather/images/";
            //if (pg === 1) w_url = "images/";
            var d = new Date();
            var month_num = d.getMonth();
            var week_num = d.getDay();
            var day = d.getDate();
            var hours = d.getHours();
            var minutes = d.getMinutes();
            var seconds = d.getSeconds();
            month = new Array("января", "февраля", "марта", "апреля", "мая", "июня",
                "июля", "августа", "сентября", "октября", "ноября", "декабря");
            week = new Array("воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота");
            if (day <= 9) day = "0" + day;
            if (hours <= 9) hours = "0" + hours;
            if (minutes <= 9) minutes = "0" + minutes;
            if (seconds <= 9) seconds = "0" + seconds;


            temp = Math.round(temp);
            f_l = Math.round(f_l);
            pressure = Math.round(pressure);
            h1 = Math.floor(set_rise / 3600);
            set_rise = set_rise - h1 * 3600;
            m1 = Math.floor(set_rise / 60);
            if (h1 < 10) h1 = "0" + h1;
            if (m1 < 10) m1 = "0" + m1;
            set_rise = h1 + ":" + m1;
            y1 = Math.floor(sunrise / (3600 * 24 * 365));
            sunrise = sunrise - y1 * (3600 * 24 * 365);
            d1 = Math.floor(sunrise / (3600 * 24));
            sunrise = sunrise - d1 * (3600 * 24) + t_z;
            h1 = Math.floor(sunrise / 3600);
            sunrise = sunrise - h1 * 3600;
            m1 = Math.floor(sunrise / 60);
            if (h1 < 10) h1 = "0" + h1;
            if (m1 < 10) m1 = "0" + m1;
            sunrise = h1 + ":" + m1;
            y1 = Math.floor(sunset / (3600 * 24 * 365));
            sunset = sunset - y1 * (3600 * 24 * 365);
            d1 = Math.floor(sunset / (3600 * 24));
            sunset = sunset - d1 * (3600 * 24) + t_z;
            h1 = Math.floor(sunset / 3600);
            sunset = sunset - h1 * 3600;
            m1 = Math.floor(sunset / 60);
            if (h1 < 10) h1 = "0" + h1;
            if (m1 < 10) m1 = "0" + m1;
            sunset = h1 + ":" + m1;
            if (((w_d >= 351) && (w_d <= 360)) || ((w_d >= 0) && (w_d <= 11))) w_d = "северный";
            if (((w_d >= 12) && (w_d <= 34))) w_d = "северо-северо-восточный";
            if (((w_d >= 35) && (w_d <= 56))) w_d = "северо-восточный";
            if (((w_d >= 57) && (w_d <= 80))) w_d = "восточно-северо-восточный";
            if (((w_d >= 81) && (w_d <= 102))) w_d = "восточный";
            if (((w_d >= 103) && (w_d <= 125))) w_d = "восточно-юго-восточный";
            if (((w_d >= 126) && (w_d <= 148))) w_d = "юго-восточный";
            if (((w_d >= 149) && (w_d <= 170))) w_d = "юго-юго-восточный";
            if (((w_d >= 171) && (w_d <= 193))) w_d = "южный";
            if (((w_d >= 194) && (w_d <= 215))) w_d = "юго-юго-западный";
            if (((w_d >= 216) && (w_d <= 238))) w_d = "юго-западный";
            if (((w_d >= 239) && (w_d <= 260))) w_d = "западно-юго-западный";
            if (((w_d >= 261) && (w_d <= 283))) w_d = "западный";
            if (((w_d >= 284) && (w_d <= 305))) w_d = "западно-северо-западный";
            if (((w_d >= 306) && (w_d <= 328))) w_d = "северо-западный";
            if (((w_d >= 329) && (w_d <= 350))) w_d = "северо-северо-западный";

            date_time = '<div class="weather" style="text-align: center;height: 290px;width: 350px;border-style: outset; border-width: 5px; background-color:#000000;">' +
                '<table width="100%" height="100%" cellspasing="0" cellpadding="0">' +
                '<tr><td nowrap style="width: 100%;height: 100%background-size: cover;background-image: url(' + w_url + 'fon0.gif)">' +
                '<font style="font-size: 18pt;text-align: center;font-weight: bold" color="#00FFFF">' +
                '<p style="margin-bottom: 10px;margin-top: 2px">' + city2 + '</p>' +
                '</font>' +
                '<p style="margin-bottom: 2px;margin-top: 2px;text-align: center"><font style="font-size: 14pt; color: #FFFFFF">' + week[week_num] +
                '<br>' + day + ' ' + month[month_num] + ' ' + d.getFullYear() + '</font>' +
                '<font face="LcdD" style="font-size: 14pt;font-style: normal; color: #00FF66"> ' + hours + ':' + minutes + '</font></p>' +
                '<font style="font-size: 13pt" color="#FFFFFF">' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Погода: ' +
                '<img width="32" height="32" src="' + w_url + w_ico + '.png" alt=""><font color="#FFFF00"> ' + w_des + '</font><br>' +
                'Температура: <font color="#FFFF00">' + temp + '°C&nbsp;&nbsp;&nbsp;<font color="#FFFFFF"> По ощущению </font>' + f_l + '°C</font></p>' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Давление: <font color="#FFFF00">' + pressure + ' мм рт. ст.</font></p>' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Ветер: <font color="#FFFF00">' + w_d + ' ' + wind + ' м/с</font></p>' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Влажность: <font color="#FFFF00">' + humidity + '%</font></p>' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Видимость: <font color="#FFFF00">' + visibility + ' м</font></p>' +
                '<img src="' + w_url + '01d.png" width="48" height="48" alt="" align="left">' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Рассвет: <font color="#FFFF00">' + sunrise + '<font color="#FFFFFF">&nbsp;&nbsp;&nbsp;Долгота дня </font>' + set_rise + '</font></p>' +
                '<p style="margin-bottom: 2px;margin-top: 2px;margin-left: 10px;text-align: left">Закат: <font color="#FFFF00">' + sunset + '</font></p>' +
                '</font></td></tr></table></div>';
            w_out.innerHTML = date_time;
            setTimeout(() => getFile(url), delay);
        }
         document.addEventListener("DOMContentLoaded", function() {
         getFile(url);
                    })

    </script>
</body>

</html>

Последний раз редактировалось рони, 21.12.2022 в 00:04.
Ответить с цитированием
  #5 (permalink)  
Старый 21.12.2022, 00:06
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,064

к посту выше, код рабочий, песочница с http не работает, только с https, убрал запуск run.
Ответить с цитированием
  #6 (permalink)  
Старый 21.12.2022, 11:19
Новичок на форуме
Отправить личное сообщение для parshin Посмотреть профиль Найти все сообщения от parshin
 
Регистрация: 13.12.2022
Сообщений: 6

Спасибо огромное
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
API Яндекс Погода Slandewi Общие вопросы Javascript 3 05.05.2017 22:09