Skip to content

Instantly share code, notes, and snippets.

@seadog007
Last active December 16, 2015 16:42
Show Gist options
  • Save seadog007/bc8f9b8e9b70fe686d24 to your computer and use it in GitHub Desktop.
Save seadog007/bc8f9b8e9b70fe686d24 to your computer and use it in GitHub Desktop.
#!/bin/bash
# If you are using OSX, you can use `brew install jq` to install jq library
# If you are using Debian, Ubuntu, or something, then you can use `sudo apt-get install jq`
# I don't use yum and rpm system, so XDDDD Google it!
# Oh, Windows user? Sorry, you need a unix system.
while read input
do
res=`curl -s "https://codein.withgoogle.com/api/program/2015/taskdefinition/$input/"`
detail=`echo $res | jq .detail`
if [ "$detail" = '"Not found."' ]
then
echo "Warning: your input is not taskid, try to covert to taskid."
taskid=`curl -s -D - "https://codein.withgoogle.com/dashboard/task-instances/$input/" | grep Location | grep -oh '[[:digit:]]\+'`
res=`curl -s "https://codein.withgoogle.com/api/program/2015/taskdefinition/$taskid/"`
testdata=`echo "$res" | jq .name`
[ "$testdata" = "null" ] && echo "Still wrong, please check your input" && exit 1
[ "$testdata" != "null" ] && echo "Guess correct, the id is instance id." && echo "Task ID of $input is: $taskid" && echo ''
fi
# Base data
name=`echo "$res" | jq -r .name`
claimed_count=`echo "$res" | jq .claimed_count`
max_instances=`echo "$res" | jq .max_instances`
[ "$name" != "null" ] && echo -e "$name\t$claimed_count/$max_instances"
done < tasklist
@seadog007
Copy link
Author

My example tasklist:
2015-12-17 12 41 04

@seadog007
Copy link
Author

The result:
2015-12-17 12 40 55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment