Skip to content

Instantly share code, notes, and snippets.

@dermorz
Last active March 5, 2022 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermorz/d9e9e4f0cd6f6ef25a3b1017b441fad4 to your computer and use it in GitHub Desktop.
Save dermorz/d9e9e4f0cd6f6ef25a3b1017b441fad4 to your computer and use it in GitHub Desktop.
Minimal bash implementation of a sc2replaystats.com uploader. Requirements: inotify-tools, curl, awk
#!/bin/bash
#
# Usage: ./sc2replaystats.sh
#
# Keep one instance of this script running when playing Starcraft II.
# For example run it with systemd in user-space so it's just always running when logged in.
# Better output on errors
set -euxo pipefail
# I have a symlink from $HOME/replays to "$HOME/StarCraft II/Accounts/{ID}/{TOON_ID}/Replays/Multiplayer".
# You can also just put the direct path here.
REPLAYS="$HOME/replays"
# Create curl version string to use as upload method in API call.
CURL_VERSION=$(curl --version | head -n 1 | awk '{ print $1 "-" $2 }')
# sc2replaystats API config
SC2RS_API=https://api.sc2replaystats.com
SC2RS_AUTHKEY="your api authentication key here"
# Watch the replay folder for newly created files (ignores renames)
inotifywait --monitor --event close_write --format "%f" "${REPLAYS}" \
| while read FILENAME
do
# Only process SC2Replay files
[[ $FILENAME != *.SC2Replay ]] && continue
# Get absolute file path
REPLAY_FILE=$(realpath "${REPLAYS}/${FILENAME}")
# Upload replay via API call
curl \
-H "Authorization: ${SC2RS_AUTHKEY}" \
-F "upload_method=${CURL_VERSION}" \
-F "replay_file=@${REPLAY_FILE}" \
"${SC2RS_API}/replay"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment