Skip to content

Instantly share code, notes, and snippets.

@desrod
Created May 25, 2020 00:01
Show Gist options
  • Save desrod/6629f50f48394f95fcc3deccdeb23dc3 to your computer and use it in GitHub Desktop.
Save desrod/6629f50f48394f95fcc3deccdeb23dc3 to your computer and use it in GitHub Desktop.
Query Zwift public, upcoming events and build an HTML table of those events (in shell)
There are two parts to this:
1. The main shell script that calls curl and jq
2. The jq filter itself, an external file
# ----------------------------------------------------------------------------------------------------------------
#!/bin/bash
events=$(curl --compressed -s 'https://us-or-rly101.zwift.com/api/public/events/upcoming')
read -r -d '' html_header << EOM
<html>
<head><title>Visible to Non-Participants</title>
<style>
table {font-family: "Courier New", monospace; font-size:0.8em; border-collapse: collapse;}
table, th, tr, td {border: 1px solid #ccc; padding:0.3em;}
th {text-align: center;} td {text-align:right;}
td.l {text-align:left;}
tr:nth-child(even) {background: #eee;}
</style>
</head>
<table>
<thead>
<tr>
<th>Kilometers</th>
<th>Minutes</th>
<th>Laps</th>
<th>Activity</th>
<th>Start time</th>
<th>Link</th>
</tr>
</thead>
<tbody>
EOM
html_footer='</tbody></table></html>'
echo "$html_header"
echo "$events" | jq -r -f events-filter.jq
echo "$html_footer"
# ----------------------------------------------------------------------------------------------------------------
.[] | select(.invisibleToNonParticipants == false) | "<tr>
<td>\(.distanceInMeters / 1000)</td>
<td>\(.durationInSeconds / 60)</td>
<td>\(.laps)</td>
<td>\(.sport) \(.eventType)</td>
<td class=\"l\">\(.eventStart | strptime("%Y-%m-%dT%H:%M:%S.000+0000") | mktime | strftime("%F %X%z (%Z) %A"))</td>
<td class=\"l\"><a href=\"https://zwift.com/events/view/\(.id)\">\(.name)</a></td>
</tr>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment