问题描述
我一直在修改天气 API,并最终让它在网站内运行。遗憾的是,我需要将信息发送到 RSS 提要中,以便它可以与我的电视硬件配合使用。
数据为 JSON
{
"observation": {
"dewPoint": 50.3,"humidity": 45.0,"pressureSeaLevel": 29.98,"rainDaily": 0.0,"temperature": 72.8,"windSpeed": 5.7,"windDirection": 99,},}
<html lang="en">
<head>
<Meta charset="UTF-8" />
<Meta name="viewport" content="width=\,initial-scale=1.0" />
<Meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Weather for School</title>
</head>
<body>
<p>
Temp: <span id="TempF"></span>F<br />
Wind: <span id="WindS"></span><br />
Humidity: <span id="Humdi"></span>%<br />
Feels Like: <span id="TempL"></span>F<br />
Rain: <span id="RainD"></span> INCH<br />
Pressure: <span id="Press"></span>"<br />
Dew Point: <span id="DewPt"></span>F<br />
</p>
<script>
const api_url = 'https://10.10.115.33/Weather';
let firstTime = true;
async function getWeather(direction) {
const response = await fetch(api_url);
const data = await response.json();
const { temperature,humidity,feelsLike,windSpeed,windDirection,rainDaily } = data;
var direction = getwindDirection(data.observation.windDirection);
var FullWind = ' ' + direction + ' ' + data.observation.windSpeed + ' MPH ';
if(data.observation.windSpeed > 3){
document.getElementById('WindS').textContent = FullWind;
}
else{
document.getElementById('WindS').textContent = 'CALM';
}
document.getElementById('TempF').textContent = data.observation.temperature;
document.getElementById('TempL').textContent = data.observation.feelsLike;
document.getElementById('Humdi').textContent = data.observation.humidity;
document.getElementById('RainD').textContent = data.observation.rainDaily;
document.getElementById('DewPt').textContent = data.observation.dewPoint;
document.getElementById('Press').textContent = data.observation.pressureSeaLevel;
}
function getwindDirection(direction) {
var wndDir = "N";
if (((direction >= 349) && (direction <= 359)) || ((direction >= 0) && (direction <= 11))) {
wndDir = "N";
} else if ((direction >= 12) && (direction <= 34)) {
wndDir = "NNE";
} else if ((direction >= 35) && (direction <= 56)) {
wndDir = "NE";
} else if ((direction >= 57) && (direction <= 78)) {
wndDir = "ENE";
} else if ((direction >= 79) && (direction <= 101)) {
wndDir = "E";
} else if ((direction >= 102) && (direction <= 123)) {
wndDir = "ESE";
} else if ((direction >= 124) && (direction <= 146)) {
wndDir = "SE";
} else if ((direction >= 147) && (direction <= 168)) {
wndDir = "SSE";
} else if ((direction >= 169) && (direction <= 191)) {
wndDir = "S";
} else if ((direction >= 192) && (direction <= 213)) {
wndDir = "SSW";
} else if ((direction >= 214) && (direction <= 236)) {
wndDir = "SW";
} else if ((direction >= 237) && (direction <= 258)) {
wndDir = "WSW";
} else if ((direction >= 259) && (direction <= 281)) {
wndDir = "W";
} else if ((direction >= 282) && (direction <= 303)) {
wndDir = "WNW";
} else if ((direction >= 304) && (direction <= 326)) {
wndDir = "NW";
} else if ((direction >= 327) && (direction <= 348)) {
wndDir = "NNW";
}
return wndDir;
}
getWeather();
setInterval(getWeather,10000);
</script>
</body>
</html>
从我读过的内容来看,我可能不得不将其全部转换为 PHP,但如果可以的话,我宁愿避免这样做(我大麦记得大学时的 Java/JavaScript)。 我确实有一个可以运行 Node.JS 的 Asustor NAS。我想做什么:
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)