PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/train.sh

http://gsbabil.googlecode.com/
Shell | 106 lines | 81 code | 22 blank | 3 comment | 15 complexity | 5ec7e278f55ad41b0a05d6a8b2d155ee MD5 | raw file
  1#!/bin/bash -e
  2
  3print_url=0
  4timeout=10
  5
  6from_sta='Redfern'
  7dest_sta='Blacktown'
  8
  9old_now_date=$(date +%d%%2F%m%%2F%y)
 10old_now_time=$(date +%I%%3A%M%p)
 11
 12now_date=$(date +%Y%m%d)
 13now_hour=$(date +%I)
 14now_min=$(date +%M)
 15now_ampm=$(date +%P)
 16
 17function usage()
 18{
 19echo
 20cat <<EOF
 21[*] usage: `basename $0`  options
 22
 23OPTIONS:
 24	-u	print url
 25	-h	show this message
 26	-a	set from station
 27	-b	set dest. station
 28	-t	set search time (08:30AM)
 29	-d	set search date (21/5/10)
 30EOF
 31echo
 32exit
 33}
 34
 35function get_cookie()
 36{
 37	wget -q -O /dev/null --keep-session-cookies --save-cookies="cookie.txt" "${1}"
 38}
 39
 40while getopts "uha:b:t:d:" flag
 41do
 42	if [ "$flag" == 'u' ]
 43	then
 44		print_url=1
 45	fi
 46
 47	if [ "$flag" == 'h' ]
 48	then
 49		usage
 50	fi
 51
 52	if [ "$flag" == 'a' ]
 53	then
 54		A=$(echo -n "${OPTARG:0:1}" | tr "[:lower:]" "[:upper:]") 
 55		from_sta="$(echo -n "${A}${OPTARG:1}" | sed 's/ /+/g')"
 56	fi
 57
 58	if [ "$flag" == 'b' ]
 59	then
 60		A=$(echo -n "${OPTARG:0:1}" | tr "[:lower:]" "[:upper:]") 
 61		dest_sta="$(echo -n "${A}${OPTARG:1}" | sed 's/ /+/g')"
 62	fi
 63
 64	if [ "$flag" == 't' ]
 65	then
 66		now_time=$(echo -n "$OPTARG" | tr '[:lower:]' '[:upper:]')
 67		now_time=$(echo "$now_time" | sed 's/://g;s/\-//g;s/\///g;s/\\//g')
 68
 69		now_hour=$(echo -n "${now_time:0:2}")
 70		now_min=$(echo -n "${now_time:2:2}")
 71		now_ampm=$(echo -n "${now_time:4:2}")
 72	fi
 73	
 74	if [ "$flag" == 'd' ]
 75	then
 76		now_date="$OPTARG"
 77		now_date=$(echo "$now_date" | sed 's/://g;s/\-//g;s/\///g;s/\\//g')
 78	fi
 79done
 80
 81old_url="http://www.131500.com.au/fullEnquiry.asp?&Vehicle=Bus,Train,Ferry&WalkSpeed=NORMAL&&IsAfter=A&MaxChanges=-1&FromLocType=s&ToLocType=s&x=64&y=11&FromLoc=$from_sta+Station~~;$from_sta+Station;$from_sta+Station~~LOCATION&ToLoc=$dest_sta+Station~~;$dest_sta+Station;$dest_sta+Station~~LOCATION&Time=$now_time&Date=$now_date"
 82
 83ori_url='http://www.131500.com.au/plan-your-trip/trip-planner?session=invalidate&itd_cmd=invalid&itd_includedMeans=checkbox&itd_inclMOT_5=1&itd_inclMOT_7=1&itd_inclMOT_1=1&itd_inclMOT_9=1&itd_anyObjFilter_origin=2&itd_name_origin=redfern&itd_anyObjFilter_destination=2&itd_name_destination=blacktown&itd_itdDate=20100824&itd_itdTripDateTimeDepArr=dep&itd_itdTimeHour=2&itd_itdTimeMinute=0&itd_itdTimeAMPM=pm&x=56&y=11'
 84
 85url="http://www.131500.com.au/plan-your-trip/trip-planner?session=invalidate&itd_cmd=invalid&itd_includedMeans=checkbox&itd_inclMOT_5=1&itd_inclMOT_7=1&itd_inclMOT_1=1&itd_inclMOT_9=1&itd_anyObjFilter_origin=2&itd_name_origin=${from_sta}&itd_anyObjFilter_destination=2&itd_name_destination=${dest_sta}&itd_itdDate=${now_date}&itd_itdTripDateTimeDepArr=dep&itd_itdTimeHour=${now_hour}&itd_itdTimeMinute=${now_min}&itd_itdTimeAMPM=${now_ampm}&x=56&y=11"
 86
 87if [ $print_url == '1' ]
 88then
 89	echo $url
 90fi
 91
 92echo
 93echo "From: $from_sta Station"
 94echo "Dest: $dest_sta Station"
 95echo "Time: $(echo $now_hour:$now_min $now_ampm | sed 's/\%3A/:/g')"
 96echo "Date: $(echo ${now_date:0:4}:${now_date:4:2}:${now_date:6:2} | sed 's/\%2F/\//g')"
 97echo
 98
 99referer='http://www.131500.com.au/'
100agent='Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729)'
101
102#get_cookie $url
103#wget $url -q -O - --referer "$referer" --load-cookies=cookie.txt --user-agent="$agent" | html2text | grep 'Option \([0-9]\+\)\|Arr:\|Dep:'
104lynx -noredir -dump $url | grep 'Option \([0-9]\+\)\|Arr:\|Dep:'
105
106echo