2021-03-27 21:50:52 +00:00
|
|
|
{{$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">
|
2021-03-28 02:59:15 +00:00
|
|
|
<progress class="progress is-light" id="weatherLoading_{{$randID}}"></progress>
|
2021-03-26 05:25:10 +00:00
|
|
|
<div class="columns is-mobile">
|
|
|
|
<div class="column is-half">
|
2021-03-27 21:50:52 +00:00
|
|
|
<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">
|
2021-03-27 21:50:52 +00:00
|
|
|
<p id="weatherTempText_{{$randID}}" class="has-text-right subtitle"></p>
|
2021-03-26 05:25:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-27 21:50:52 +00:00
|
|
|
<p class="subtitle is-marginless" 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>
|
2021-03-28 02:59:15 +00:00
|
|
|
<div class="card-footer">
|
2021-03-26 05:25:10 +00:00
|
|
|
<span class="card-footer-item">Data from <a href="https://www.metaweather.com" class="has-text-info">Metaweather</a></span>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var request = new XMLHttpRequest()
|
2021-03-27 21:50:52 +00:00
|
|
|
request.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)}
|
|
|
|
request.onload = function () {
|
|
|
|
const data = JSON.parse(this.response)
|
2021-03-28 02:59:15 +00:00
|
|
|
document.getElementById('weatherLoading_{{$randID}}').classList.add("is-hidden")
|
2021-03-27 21:50:52 +00:00
|
|
|
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) + " °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) + " °F"
|
|
|
|
document.getElementById('weatherMaxText_{{$randID}}').innerHTML = "Max: " + round(data["consolidated_weather"][0]["max_temp"]*1.8+32) + " °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
|
|
|
}
|
|
|
|
request.send()
|
|
|
|
</script>
|