Skip to content

Instantly share code, notes, and snippets.

@mastensg
Created February 15, 2016 11:44
Show Gist options
  • Save mastensg/1bd3beab2a2ee2f23aed to your computer and use it in GitHub Desktop.
Save mastensg/1bd3beab2a2ee2f23aed to your computer and use it in GitHub Desktop.
#!/bin/sh
CACHE="/tmp/p2k12_users"
update_cache() {
curl -s https://p2k12.bitraf.no/users |
awk '{printf $NF ":" $1; for(i=2;i<NF;++i){printf " "$i;}print ""}' | sort > $CACHE
}
test -f $CACHE || update_cache
curl -s "https://p2k12.bitraf.no/checkins/?interval=2+days&media-type=application%2Fvnd.bitraf.checkins-json" |
jq -r '[.[] | [.date[:16], .name] | join("\t")] | join("\n")' | (
while true
do
read line || break
time=$(echo "$line" | cut -f 1)
user=$(echo "$line" | cut -f 2)
name=$(look "$user:" $CACHE | head -1 | cut -d: -f 2 | sed 's/ /_/g')
echo "$time $user $name"
done
) | column -t | sed 's/_/ /g' | awk '{if (!x) {x=$1} else if (x != $1) {x=$1} else {sub(/^........../, " ", $0)} print $0}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment