This repository has been archived on 2021-05-23. You can view files and clone it, but cannot push or open issues or pull requests.
simpledash/resources/templates/cards/weather.html

46 lines
3.0 KiB
HTML
Raw Normal View History

{{$randID := randAlphaNum 10}}
2021-03-26 05:25:10 +00:00
<div class="card-header">
<p class="card-header-title">{{.Title}}</p>
</div>
<div class="card-content">
<progress class="progress is-light" id="weatherLoading_{{$randID}}"></progress>
2021-03-26 05:25:10 +00:00
<div class="columns is-mobile">
2021-03-31 18:59:53 +00:00
<div class="column is-half" style="padding-bottom: 0;">
<object type="image/svg+xml" id="weatherStateImg_{{$randID}}" style="width:45px; height: 45px"></object>
2021-03-26 05:25:10 +00:00
</div>
<div class="column is-half">
<p id="weatherTempText_{{$randID}}" class="has-text-right subtitle"></p>
2021-03-26 05:25:10 +00:00
</div>
</div>
2021-03-31 18:59:53 +00:00
<p class="subtitle" id="weatherStateText_{{$randID}}"></p>
<p id="weatherMinText_{{$randID}}"></p>
<p id="weatherMaxText_{{$randID}}"></p>
<p id="weatherWindSpeedText_{{$randID}}"></p>
<p id="weatherHumidityText_{{$randID}}"></p>
<p id="weatherVisibilityText_{{$randID}}"></p>
<p id="weatherPredictabilityText_{{$randID}}"></p>
2021-03-26 05:25:10 +00:00
</div>
<div class="card-footer">
2021-03-26 05:25:10 +00:00
<span class="card-footer-item">Data from&nbsp;<a href="https://www.metaweather.com" class="has-text-info">Metaweather</a></span>
</div>
<script>
var wtrRequest = new XMLHttpRequest()
wtrRequest.open('GET', "{{proxy (printf `https://www.metaweather.com/api/location/%s/` .Data.woeid)}}", true)
2021-03-26 05:25:10 +00:00
const round = function (flt){return Number.parseFloat(flt).toPrecision(3)}
wtrRequest.onload = function () {
2021-03-26 05:25:10 +00:00
const data = JSON.parse(this.response)
document.getElementById('weatherLoading_{{$randID}}').classList.add("is-hidden")
document.getElementById('weatherStateText_{{$randID}}').innerText = data["consolidated_weather"][0]["weather_state_name"]
document.getElementById('weatherTempText_{{$randID}}').innerHTML = round(data["consolidated_weather"][0]["the_temp"]*1.8+32) + " &deg;F"
document.getElementById('weatherStateImg_{{$randID}}').data = "/proxy/" + btoa("https://www.metaweather.com/static/img/weather/" + data["consolidated_weather"][0]["weather_state_abbr"] + ".svg")
document.getElementById('weatherMinText_{{$randID}}').innerHTML = "Min: " + round(data["consolidated_weather"][0]["min_temp"]*1.8+32) + " &deg;F"
document.getElementById('weatherMaxText_{{$randID}}').innerHTML = "Max: " + round(data["consolidated_weather"][0]["max_temp"]*1.8+32) + " &deg;F"
document.getElementById('weatherWindSpeedText_{{$randID}}').innerText = "Wind Speed: " + round(data["consolidated_weather"][0]["wind_speed"]) + "mph"
document.getElementById('weatherHumidityText_{{$randID}}').innerText = "Humidity: " + data["consolidated_weather"][0]["humidity"] + "%"
document.getElementById('weatherVisibilityText_{{$randID}}').innerText = "Visibility: " + round(data["consolidated_weather"][0]["visibility"]) + "mi"
document.getElementById('weatherPredictabilityText_{{$randID}}').innerText = "Predictability: " + data["consolidated_weather"][0]["predictability"] + "%"
2021-03-26 05:25:10 +00:00
}
wtrRequest.setRequestHeader("Content-Type", "text/plain")
wtrRequest.send()
2021-03-26 05:25:10 +00:00
</script>