Last active
March 9, 2020 01:36
-
-
Save elzup/4aac08e2fcb458f0477fbc8cf9133c6d to your computer and use it in GitHub Desktop.
create atcoder badge. (ex. `./make_badge.sh anozon`
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/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
example: