Created
April 22, 2015 23:47
-
-
Save snapcase/7181d8d343f260903382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# list of heroes and the id used to display their icons | |
typeset -A heroes | |
heroes=( | |
122 "Abathur" 362 "Anub'arak" 345 "Arthas" 371 "Azmodan" 354 "Brightwing" 381 "Chen" 321 "Diablo" 312 "E.T.C." | |
220 "Falstad" 155 "Gazlowe" 196 "Illidan" 393 "Jaina" 233 "Kerrigan" 114 "Li Li" 277 "Malfurion" 329 "Muradin" | |
412 "Murky" 144 "Nazeebo" 259 "Nova" 133 "Raynor" 432 "Rehgar" 285 "Sgt. Hammer" 249 "Sonya" 337 "Stitches" | |
439 "Sylvanas" 165 "Tassadar" 403 "The Lost Vikings" 451 "Thrall" 182 "Tychus" 303 "Tyrael" 173 "Tyrande" | |
420 "Uther" 268 "Valla" 459 "Zagara" 294 "Zeratul" | |
) | |
# page to scrape for information | |
url="http://heroesofthestorm.github.io/free-hero-rotation" | |
# retrieve the weekly hero rotation | |
typeset -a weekly | |
weekly=(${(f)"$(wget -qO- $url | \ | |
sed -n '/<h2>/{:loop n; s|.*type="button">\([^<]*\)</button>$|\1|p; /<h2>/q; b loop}')"}) | |
local_checksum=$(getfattr --only-values -n user.checksum "$0" 2>/dev/null) | |
remote_checksum=${$(echo ${weekly[@]} | md5sum)[(w)1]} | |
# only run on updates | |
if [[ $local_checksum != $remote_checksum ]]; then | |
# update checksum | |
setfattr -n user.checksum -v "$remote_checksum" "$0" | |
# retrieve random hero id | |
hero=${${(k)heroes}[RANDOM%$#heroes+1]} | |
# strings for payload | |
text="<$url|Free Week Rotation for Heroes of the Storm:>\n${(j:, :)weekly}" | |
icon_url="http://media.heroesnexus.com/avatars/thumbnails/346/$hero/65/65/icon.png" | |
# post to slack | |
curl \ | |
-X POST \ | |
--data-urlencode \ | |
'payload={"text": "'$text'", "channel": "#hots", "username": "'${heroes[$hero]}'", "icon_url": "'$icon_url'"}' \ | |
https://hooks.slack.com/services/my/secret/url | |
else | |
echo "nothing to do" | |
fi | |
# vim: nowritebackup nobackup noswapfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment