4 01 2011

抢火车票的脚本

bigCat Posted in Linux - Comment.isBlank

http://www.notedit.com/2010/11/%E6%8A%A2%E7%81%AB%E8%BD%A6%E7%A5%A8%E7%9A%84%E7%A8%8B%E5%BA%8F/\r\n\r\n

#!/bin/bash\r\nexport DISPLAY=:0\r\nURL_58='http://www.58.com/huochepiao/beijing-wuhan/'\r\n\r\nCURRENTDIR=$( pwd )\r\nTMPFILE="$CURRENTDIR/$$"\r\nWGET="wget --timeout 30 --tries=1 --limit-rate=50k"\r\n\r\nusage()\r\n{\r\n{\r\necho "first you run $(basename $0) ready"\r\necho "then you run $(basename $0 ) run"\r\necho " bula bula~~"\r\n} >&2\r\n\r\n}\r\n\r\nget_ready()\r\n{\r\nrm -rf *.html\r\n$WGET -O- "$URL_58" |  grep -oE '[0-9]{13}' > 2.html\r\necho "ready"\r\n}\r\nget_our_tickets()\r\n{\r\n\r\necho "ticket" >> test.txt\r\n$WGET -O- "$URL_58" |  grep -E -A 1 '[0-9]{13}'\r\n| sed -e 's/--//g' -e 's/ //g' -e '/^$/d' > 3.html\r\ncat 3.html | grep -oE '[0-9]{13}' > 4.html\r\ncat 3.html | grep -oE '[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}'\r\n> 5.html\r\npaste 4.html 5.html >6.html\r\nwhile read line;do\r\nid=$( echo $line | awk '{ print $1 }' )\r\nday=$( echo $line | awk '{print $2 }' )\r\nif grep -qF "$id" 2.html;then\r\ncontinue\r\nelse\r\nnotify-send "you get a ticket" "$day"\r\necho $id >> 2.html\r\nfi\r\ndone < 6.html\r\n\r\n}\r\n\r\ntouch "$TMPFILE"\r\n\r\narg=$1\r\n\r\nif [[ -n $arg ]];then\r\ncase $arg in\r\nready)\r\nget_ready\r\n;;\r\nrun)\r\nget_our_tickets\r\n;;\r\nesac\r\nfi

Host: (miao) | Word: Press | Code: HTML5