Skip to content

Instantly share code, notes, and snippets.

@elzup
Created March 9, 2020 01:32
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 elzup/f0ecb33d65b8cb538461d08646283a40 to your computer and use it in GitHub Desktop.
Save elzup/f0ecb33d65b8cb538461d08646283a40 to your computer and use it in GitHub Desktop.
#!/bin/bash
# this script dependence "pup", "jq"
USERNAME=$1
SELECTOR='tr:nth-child(2) span:nth-child(1) json{}'
USERDATA=$(curl -s https://atcoder.jp/users/$USERNAME |pup $SELECTOR)
COLOR=$(echo $USERDATA |jq --raw-output ".[0].class" |sed 's/user-//')
RATE=$(echo $USERDATA |jq --raw-output ".[0].text")
COLORCODE=$(echo '{
"red": "#FF0000",
"orange": "#FF8000",
"yellow": "#C0C000",
"blue": "#0000FF",
"cyan": "#00C0C0",
"green": "#008000",
"brown": "#804000",
"gray": "#808080",
"unrated": "#000000"
}' |jq --raw-output .$COLOR |sed 's/^.//')
BADGE_URL="https://img.shields.io/badge/AtCoder-$RATE-$COLORCODE.svg"
echo user: $USERNAME
echo color: $COLOR
echo rate: $RATE
echo badge-url: $BADGE_URL
wget $BADGE_URL -q -O atcoder-badge.svg
echo successfly exported badge to ./atcoder-badge.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment