diff --git a/content/posts/display-tempest-weather-static-site/finished-product.png b/content/posts/display-tempest-weather-static-site/finished-product.png new file mode 100644 index 0000000..53894a5 Binary files /dev/null and b/content/posts/display-tempest-weather-static-site/finished-product.png differ diff --git a/content/posts/display-tempest-weather-static-site/index.md b/content/posts/display-tempest-weather-static-site/index.md index 35d5eba..9b1643f 100644 --- a/content/posts/display-tempest-weather-static-site/index.md +++ b/content/posts/display-tempest-weather-static-site/index.md @@ -3,20 +3,24 @@ title: "Displaying Data from Tempest Weather Station on a Static Site" date: 2024-02-10 # lastmod: 2024-02-10 draft: true -description: "Using a GitHub Actions workflow as a sort of API proxy to retrieve data from an authenticated " +description: "Using a GitHub Actions workflow to retrieve data from an authenticated API, posting results to a publicly-accessible pastebin, and displaying them on a static web site." featured: false toc: true comments: true -categories: Tips # Backstage, ChromeOS, Code, Self-Hosting, VMware +categories: Backstage tags: - api - javascript - meta - serverless --- -As I covered briefly [in a recent Scribble](https://scribbles.jbowdre.lol/post/near-realtime-weather-on-profile-lol-ku4yq-zr), I spent some time this week with integrating data from my [Weatherflow Tempest weather station](https://shop.weatherflow.com/products/tempest) into my [omg.lol homepage](https://jbowdre.lol). That page is rendered as a static site, so I needed a way to do this *without* including secrets like the station ID or API token in the client-side JavaScript. +As I covered briefly [in a recent Scribble](https://scribbles.jbowdre.lol/post/near-realtime-weather-on-profile-lol-ku4yq-zr), I was inspired by the way [Kris's omg.lol page](https://kris.omg.lol/) displays realtime data from his [Weatherflow Tempest weather station](https://shop.weatherflow.com/products/tempest). I thought that was really neat and wanted to do the same on [my omg.lol page](https://jbowdre.lol) with data from my own Tempest, but I wanted to do it without including my station ID or API token directly in the client-side JavaScript. -I realized I could use a GitHub Actions workflow to retrieve the data from the authenticated Tempest API, post it somewhere publicly accessible, and then have the client-side code fetch the data from there without needing any authentication. This post will cover how I did it. +I realized I could use a GitHub Actions workflow to retrieve the data from the authenticated Tempest API, post it somewhere publicly accessible, and then have the client-side code fetch the data from there without needing any authentication. After a few days of tinkering, I came up with a presentation I'm happy with. + +![Glowing green text on a dark grey background showing weather data like conditions, temperature, and pressure, with a note that the data is 2 minutes old](finished-product.png) + +This post will cover how I did it. ### Retrieve Weather Data from Tempest API To start, I want to play with the API a bit to see what the responses look like. Before I can talk to the API, though, I need to generate a new token for my account at `https://tempestwx.com/settings/tokens`. I also make a note of my station ID, and store both of those values in my shell for easier use. @@ -276,10 +280,12 @@ defaults: ``` The `on` block defines when the workflow will run: -1. On a `cron` schedule which fires (roughly) every five minutes +1. On a schedule which fires (roughly[^cron]) every five minutes 2. On a `workflow_dispatch` event (so I can start it manually if I want) 3. When changes are pushed to the `main` branch +[^cron]: Per [the docs](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule), runs can run *at most* once every five minutes, and they may be delayed (or even canceled) if a runner isn't available due to heavy load. + And the `defaults` block makes sure that the following scripts will be run in `bash`: ```yaml @@ -317,4 +323,575 @@ jobs: Each step in the `jobs` section should look pretty familiar since those are almost exactly the commands that I used earlier. The only real difference is that they now use the format `${{ secrets.SECRET_NAME }}` to pull in the repository secrets I just created. -Once I save, commit, and push this new file to the repo, it will automatically execute, and I can go to the [Actions](https://github.com/jbowdre/lolz/actions) tab to confirm that the run was succesful. I can also check `https://paste.jbowdre.lol/tempest.json` to confirm that the contents have updated. \ No newline at end of file +Once I save, commit, and push this new file to the repo, it will automatically execute, and I can go to the [Actions](https://github.com/jbowdre/lolz/actions) tab to confirm that the run was succesful. I can also check `https://paste.jbowdre.lol/tempest.json` to confirm that the contents have updated. + +### Show Weather on Homepage +By this point, I've fetched the weather data from Tempest, filtered it for just the fields I want to see, and posted the condensed JSON to a publicly-accessible pastebin. Now I just need to figure out how to make it show up on my omg.lol homepage. Rather than implementing these changes on the public site right away, I'll start with a barebones `tempest.html` that I can test with locally. Here's the initial structure that I'll be building from: + +```html + + + +
+ + +