Skip to content

Instantly share code, notes, and snippets.

@Widdershin
Last active Apr 24, 2018
Embed
What would you like to do?
# requires anybar https://github.com/tonsky/AnyBar (brew cask install anybar)
# to get your player_id and your authorization_header, open the devtools and go to the network inspector
# refresh the games list, and then inspect the /games request
# set authorization_header to the value of the authorization header
# you can find your steam id in the json response of that same request
#
# to automatically update, make a cronjob
# run crontab -e and add this line
#
# * * * * ruby <path-to-this-script>
#
# that should update every minute
#
# enjoy :)
require 'json'
require 'socket'
player_id = '<fill me in>'
hashed_password = '<fill me in>'
def anybar(color)
socket = UDPSocket.new
socket.connect 'localhost', '1738'
socket.send color, 0
socket.close
end
if `ps x | grep 'AnyBar' | grep -v 'grep'`.strip == ''
puts 'Starting AnyBar'
`open -a AnyBar`
end
if `ps x | grep Civ6 | grep -v grep`.strip != ''
puts 'Civ is running! Play your turn or close it!'
anybar('orange')
exit
end
games_json = `curl 'https://api.playyourdamnturn.com/user/games' -s -H 'authorization: #{hashed_password}' -H 'accept: application/json' &2>/dev/null`
games = JSON.parse(games_json)
playing = games['data'].any? { |game| game['currentPlayerSteamId'] == player_id }
if playing
color = 'exclamation'
puts 'Play your damn turn!'
else
color = 'white'
puts 'Wait your damn turn!'
end
anybar(color)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment