-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbstation.rb
43 lines (31 loc) · 928 Bytes
/
dbstation.rb
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
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'xml'
input = ARGV[0]
input2 = ARGV[1]
if (ARGV[0] != nil && ARGV[1] != nil)
i = ARGV[0]+' '+ARGV[1]
else
i = ARGV[0]
end
$stdout.puts "Suchergebnisse fuer : #{i} \n\n"
url = URI.parse('http://reiseauskunft.bahn.de/bin/mgate.exe/dn')
request = Net::HTTP::Post.new(url.path)
request.body ="<?xml version='1.0' encoding='utf-8' ?>
<ReqC ver='1.1' prod='String' lang='DE'>
<LocValReq id='req' maxNr='10' sMode='1'>
<ReqLoc type='ALLTYPE' match='#{i}'/>
</LocValReq>
</ReqC>"
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
source = XML::Parser.string(response.body)
content = source.parse
stations = content.find('//Station')
stations.each do |station|
name = station["name"]
id = station["externalStationNr"]
x = station["x"]
y = station["y"]
$stdout.puts "#{name} - #{id} - #{x} - #{y}"
end