Skip to content

Instantly share code, notes, and snippets.

@RobbiNespu
Last active October 9, 2021 05:09
Show Gist options
  • Save RobbiNespu/89be9c34f82adc82d19338f0cfd4cc3e to your computer and use it in GitHub Desktop.
Save RobbiNespu/89be9c34f82adc82d19338f0cfd4cc3e to your computer and use it in GitHub Desktop.
{{/* Hugo shortcode to get Malaysia forecast from MET API | Copyright (c) 2021 Robbi Nespu | The MIT License (MIT) */}}
{{ $accessToken := "15b024277cc29a319df973c64289923220099f6e"}}
{{ $headers := dict "Authorization" (printf "METToken %s" $accessToken) }}
{{ with getJSON "https://api.met.gov.my/v2.1/data?datasetid=WARNING&datacategoryid=WINDSEA2&start_date=2021-10-09&end_date=2021-12-31" $headers }}
<table>
<tr><th>Date</th><th>From</th><th>To</th><th>Details</th></tr>
{{ range .results }}
<tr>
<td>{{ .attributes.valid_from | time.Format "02/01/06" }}</td>
<td>{{ .attributes.valid_from | time.Format ":time_short" }}</td>
<td>{{ .attributes.valid_to | time.Format ":time_full" }}</td>
<td>{{ .value.heading.en }}</td>
</tr>
{{ end }}
</table>
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment