Skip to content

Instantly share code, notes, and snippets.

@elzup

elzup/make_badge.sh

Last active Mar 9, 2020
Embed
What would you like to do?
create atcoder badge. (ex. `./make_badge.sh anozon`
#!/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
@elzup

This comment has been minimized.

Copy link
Owner Author

@elzup elzup commented Mar 9, 2020

example:

$ ./make_badge.sh anozon
user: anozon
color: 008000
rate: 1076
badge-url: https://img.shields.io/badge/AtCoder-1076-008000.svg
successfly exported badge to ./atcoder-badge.svg

elzup_competitive-pg-wrokspace

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