Last active
August 29, 2015 14:23
-
-
Save yoshida-mediba/aa5125510421a2e8d6cc to your computer and use it in GitHub Desktop.
YAPC 2015 Ticket checker
This file contains hidden or 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 | |
URL=http://peatix.com/event/87412/view | |
XPATH='//*[@id="tix-249035"]' | |
if [[ -n $(curl -s "$URL" | xmllint --nowarning --html -xpath "$XPATH" - 2>/dev/null | fgrep 'SOLD OUT') ]]; then | |
echo "YAPC2015 SOLD OUT" | |
else | |
echo "YAPC2015 BUY NOW" | |
fi |
This file contains hidden or 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 | |
function sendMailTalknote() { | |
head="Content-Type: text/plain; charset=ISO-2022-JP"; | |
from="From: notifier@example.com" | |
addr="To: g-00000-00000@mail.talknote.com" | |
body="$1" | |
body=$(echo "${body}" | nkf -Wj) | |
echo -e "${from}\n${addr}\n${head}\n\n${body}" | /usr/sbin/sendmail -t -i | |
} | |
function getYapc2015() { | |
XPATH=() | |
XPATH[0]='//\*[@id="tix-249030"]' # 1 Day Pass "A" | 一日券A (8/21, no T shirt) | |
XPATH[1]='//\*[@id="tix-249032"]' # 1 Day Pass "B" | 一日券B (8/22, no T shirt) | |
XPATH[2]='//\*[@id="tix-249034"]' # 2 Day Pass | 二日券 (8/21+8/22, no T shirt) | |
XPATH[3]='//\*[@id="tix-249035"]' # 2 Day Pass | 二日券 (8/21+8/22, w/ T shirt) | |
curl -s http://peatix.com/event/87412/view > /tmp/curl.tmp | |
for (( i = 0; i < ${#XPATH[@]}; ++i )); do | |
xmllint --html --xpath "$(echo ${XPATH[$i]} | tr -d '\\')" /tmp/curl.tmp 2>/dev/null > /tmp/curl.lint$i.tmp | |
if [[ -n $(cat /tmp/curl.lint$i.tmp | fgrep "display:none;") ]]; then | |
cat /tmp/curl.lint$i.tmp | fgrep "ticket-name" | awk -F'<|>' '{print $3}' | |
fi | |
done | |
} | |
sendMailTalknote "$(getYapc2015)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment