I post the results from the pinball tournaments I run on our site, which usually involves copying a previous post and updating all the info by hand. I took some time this week to put together a script that reads the results from matchplay and builds a post with all the right info.
It’s not enough to publish as a git repo or anything and I just wanted to have a place to keep it so it’s here for now.
ben@odin ~> cat ~/bin/tcpp
#!/bin/sh
playersjson=$(curl -s "https://app.matchplay.events/api/tournaments/$1?includePlayers=1" \
-H "Content-Type: application/json" \
-H "Accept: application/json")
finalsId=$(printf %s "$playersjson" | jq -r ".data.linkedTournamentId")
standingsids=$(curl -s "https://app.matchplay.events/api/tournaments/$finalsId/standings" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
| jq -r '.[] | .playerId')
d=$(printf %s "$playersjson" | jq -r ".data.startUtc")
shortdate=$(date --date "$d" +"%B %-d")
ifpa=$(curl -s 'https://api.ifpapinball.com/v1/calendar/search?api_key=GET_YOUR_OWN&address=Traverse%20City&m=3')
ifpatourney=$(printf %s "$ifpa" | jq -r ".calendar[] | select(.start_date == \"$(date --date "$d" +"%F")\").tournament_id")
author=1
excerpt="Results for $shortdate tourney"
case $(date --date "$d" +"%a") in
Thu)
categories="58,54"
;;
Mon)
categories="58,52"
;;
Sun)
categories="58,51"
author=8
excerpt="Results for the $shortdate Belles tourney"
;;
*)
categories="4"
;;
esac
player1=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n1 | tail -n1)).name")
player2=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n2 | tail -n1)).name")
player3=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n3 | tail -n1)).name")
player4=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n4 | tail -n1)).name")
printf "https://tcpinball.org/wp-admin/post.php?action=edit&post="
sudo -Hu www-data wp --path=/var/www/tcpinball.org \
post create \
--post_author="$author" \
--post_category="$categories" \
--post_title="$shortdate Results" \
--post_excerpt="$excerpt" \
--post_status=draft \
--porcelain \
--post_content="<!-- wp:paragraph -->
<p>Format: Group Match Play</p>
<!-- /wp:paragraph -->
<!-- wp:table {\"hasFixedLayout\":false} -->
<figure class=\"wp-block-table\"><table><thead><tr><th>Place</th><th>Player</th></tr></thead><tbody><tr><td>1st</td><td>$player1</td></tr><tr><td>2nd</td><td>$player2</td></tr><tr><td>3rd</td><td>$player3</td></tr><tr><td>4th</td><td>$player4</td></tr></tbody></table></figure>
<!-- /wp:table -->
<!-- wp:paragraph -->
<p>See the full results on <a href=\"https://app.matchplay.events/tournaments/$1\">Match Play</a> - <a href=\"https://app.matchplay.events/tournaments/$finalsId\">Finals</a> (<a href=\"https://www.ifpapinball.com/tournaments/view.php?t=$ifpatourney\">IFPA</a>).</p>
<!-- /wp:paragraph -->
"
Results table was built by dumping the content from a previous post.
2 replies on “Matchplay Posting”
relatedly i’m very pleased with my matchplay->wordpress posting script
benharri.org/matchplay-po…
just need to get bridgy publish to work with me here… would like to not have to post to bsky manually
jetpack social adding bsky would also do the trick