summaryrefslogtreecommitdiffstats
path: root/.graveyard/util/bin/vvs.de
blob: 3b7ccf9308e3015d08a00d9700e2aeeb48f94246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /bin/sh
#
# NAME
#   vvs.de - web scraper for VVS departure information
#
# SYNOPSIS
#   vvs.de ORIGIN DESTINATION [HH [MM]]
#
# EXAMPLES
#   $ vvs.de Hauptbahnhof Renningen 13 37
#
# CAVEATS
#   Acceptable operands have to be found by trial and error.
#
# BUGS
#   Probably bit rot.^_^
#
# SEE ALSO
#   mobile.vvs.de
#
# COPYRIGHT
#   All departure information is copyrighted by Verkehrs- und
#   Tarifverbund Stuttgart GmbH.  The original copyright statement can
#   be obtained online at http://www.vvs.de/impressum .
#
#   The following code is your fault.
#
set -euf

# <form action="./efaanyfield/anyfield.php" method="post" id="efaForm">
    #s/itdDateDay=/&${3-$itdDateDay}/
    #s/itdDateMonth=/&${4-$itdDateMonth}/
    #s/itdDateYear=/&${5-$itdDateYear}/

vvs_tmp=/tmp/vvs.tmp
curl -Ss http://www.vvs.de/fahrplan/ |
sed -rn "/<!-- EFA -->/,/<!-- \/EFA -->/{
    s.*<input.*name=\"([^\"]*)\".*value=\"([^\"]*)\".*/>.*\1=\2;T
    /itdTripDateTimeDepArr=arr/b
    s/(name_origin=).*/\1${1-$name_origin}/
    s/(name_destination=).*/\1${2-$name_destination}/
    ${3+s/(itdTimeHour=).*/\1${3-$itdTimeHour}/}
    ${4+s/(itdTimeMinute=).*/\1${4-$itdTimeMinute}/}
    p
}" | tr '\n' '&' | sed 's/&$//' >"$vvs_tmp"


#while read line ; do
#  test -z "$line" || echo "$line"
#done >"$vvs_tmp"

echo from: ${1-$name_origin}
echo \ \ to: ${2-$name_destination}
echo '-------------------------------------'
w3m -cols 9423 -post "$vvs_tmp" \
    -dump http://www.vvs.de/./efaanyfield/anyfield.php |
sed -rn "
  s/^ +[0-9]+ +([0-9]+:[0-9]+) +([0-9]+:[0-9]+) +([A-Z0-9 ,]+) .*$/\1 \2  \3/p
" | tr -d ,

####