Skip to content

Instantly share code, notes, and snippets.

@hibiyasleep
Last active August 17, 2019 15:52
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 hibiyasleep/7944c03ddf81a1ae8e8595d055e76273 to your computer and use it in GitHub Desktop.
Save hibiyasleep/7944c03ddf81a1ae8e8595d055e76273 to your computer and use it in GitHub Desktop.
#!/bin/zsh
ENDPOINT="http://ticket.interpark.com/Ticket/Goods/GoodsInfoJSON.asp?Flag=RemainSeat&GoodsCode=19012027&PlaceCode=11011096&PlaySeq=001&Callback="
LINK="http://ticket.interpark.com/Ticket/Goods/GoodsInfo.asp?GoodsCode=19012027"
LOCKFILE=/tmp/.fc-checked
fetch() {
curl $ENDPOINT -X GET -H "Referer: $LINK" -H 'User-Agent: Chrome' -s \
| iconv -f euckr -t utf8 \
| jq -rR 'capture("\\((?<x>.*)\\)[^)]*$").x | fromjson'
return
}
notify () {
terminal-notifier \
-title $1 \
-message "우선: $2" \
-open $LINK \
-sound default
echo
}
while true; do
TIME=$(date +'%Y/%m/%d %H:%M:%S')
JSON=$(fetch)
SUCCESS=$?
if [ $SUCCESS -ne 0 ]; then
echo -ne "\r$TIME | 가져오기 실패 "
fi
NORMAL=$(echo $JSON | jq -r '.JSON[0].RemainCnt')
PRIORITY=$(echo $JSON | jq -r '.JSON[1].RemainCnt')
echo -ne "\r$TIME | 일반: $NORMAL, 우선: $PRIORITY "
CACHED=$(cat $LOCKFILE)
echo $PRIORITY > $LOCKFILE
if [ "$PRIORITY" -ne 0 ]; then
if [ "$CACHED" -ne "$PRIORITY" ]; then
notify '티켓 변동' $PRIORITY
fi
if [ "$CACHED" -eq 0 ]; then
# open $LINK
fi
elif [ "$CACHED" -ne 0 ]; then
notify '티켓 소멸' $PRIORITY
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment