/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. print_url=0
  3. timeout=10
  4. from_sta='Redfern'
  5. dest_sta='Blacktown'
  6. old_now_date=$(date +%d%%2F%m%%2F%y)
  7. old_now_time=$(date +%I%%3A%M%p)
  8. now_date=$(date +%Y%m%d)
  9. now_hour=$(date +%I)
  10. now_min=$(date +%M)
  11. now_ampm=$(date +%P)
  12. function usage()
  13. {
  14. echo
  15. cat <<EOF
  16. [*] usage: `basename $0` options
  17. OPTIONS:
  18. -u print url
  19. -h show this message
  20. -a set from station
  21. -b set dest. station
  22. -t set search time (08:30AM)
  23. -d set search date (21/5/10)
  24. EOF
  25. echo
  26. exit
  27. }
  28. function get_cookie()
  29. {
  30. wget -q -O /dev/null --keep-session-cookies --save-cookies="cookie.txt" "${1}"
  31. }
  32. while getopts "uha:b:t:d:" flag
  33. do
  34. if [ "$flag" == 'u' ]
  35. then
  36. print_url=1
  37. fi
  38. if [ "$flag" == 'h' ]
  39. then
  40. usage
  41. fi
  42. if [ "$flag" == 'a' ]
  43. then
  44. A=$(echo -n "${OPTARG:0:1}" | tr "[:lower:]" "[:upper:]")
  45. from_sta="$(echo -n "${A}${OPTARG:1}" | sed 's/ /+/g')"
  46. fi
  47. if [ "$flag" == 'b' ]
  48. then
  49. A=$(echo -n "${OPTARG:0:1}" | tr "[:lower:]" "[:upper:]")
  50. dest_sta="$(echo -n "${A}${OPTARG:1}" | sed 's/ /+/g')"
  51. fi
  52. if [ "$flag" == 't' ]
  53. then
  54. now_time=$(echo -n "$OPTARG" | tr '[:lower:]' '[:upper:]')
  55. now_time=$(echo "$now_time" | sed 's/://g;s/\-//g;s/\///g;s/\\//g')
  56. now_hour=$(echo -n "${now_time:0:2}")
  57. now_min=$(echo -n "${now_time:2:2}")
  58. now_ampm=$(echo -n "${now_time:4:2}")
  59. fi
  60. if [ "$flag" == 'd' ]
  61. then
  62. now_date="$OPTARG"
  63. now_date=$(echo "$now_date" | sed 's/://g;s/\-//g;s/\///g;s/\\//g')
  64. fi
  65. done
  66. old_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"
  67. ori_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'
  68. 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=${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"
  69. if [ $print_url == '1' ]
  70. then
  71. echo $url
  72. fi
  73. echo
  74. echo "From: $from_sta Station"
  75. echo "Dest: $dest_sta Station"
  76. echo "Time: $(echo $now_hour:$now_min $now_ampm | sed 's/\%3A/:/g')"
  77. echo "Date: $(echo ${now_date:0:4}:${now_date:4:2}:${now_date:6:2} | sed 's/\%2F/\//g')"
  78. echo
  79. referer='http://www.131500.com.au/'
  80. agent='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)'
  81. #get_cookie $url
  82. #wget $url -q -O - --referer "$referer" --load-cookies=cookie.txt --user-agent="$agent" | html2text | grep 'Option \([0-9]\+\)\|Arr:\|Dep:'
  83. lynx -noredir -dump $url | grep 'Option \([0-9]\+\)\|Arr:\|Dep:'
  84. echo