#!/bin/sh

NULL_VAL="-1"

CURL_EXE="curl"
CURL_OPTIONS="-sG"
URL_STANFORD="https://api.foldingathome.org/user"
_NAME=$1

NAME=$(echo "$_NAME" | sed -e "s|\[|%5B|g" | sed -e "s|\]|%5D|g" | sed -e "s|&|%26|g" | sed -e "s/|/%7C/g" | sed -e "s|/|%2F|g" | sed -e "s|<|%3C|g" | sed -e "s|>|%3E|g")

#echo "NAME=$NAME"

CMD="$CURL_EXE $CURL_OPTIONS $URL_STANFORD/$NAME"

SELID=$($CMD | sed -e "s|.*id\":\([0-9A-Za-z]\+\),.*|\\1|")

[ "$(echo $SELID | grep "^[[:digit:]]*$")" ] && echo "$SELID" || echo "$NULL_VAL"

exit

