diff --git a/DVB-Scraping.mw b/DVB-Scraping.mw index 01e65ebd..651cbd97 100644 --- a/DVB-Scraping.mw +++ b/DVB-Scraping.mw @@ -1,21 +1,16 @@ =Telnet-Haltestellenmonitor= -
#!/usr/bin/env ruby
-
 require 'net/http'
 require 'socket'
 require 'rexml/document'
-
 class MultipleStations < RuntimeError
   def initialize(stations)
     @stations = stations
   end
-
   def to_s
     "Mehrere mögliche Haltestellen: " + @stations.join(', ')
   end
 end
-
 class StationResult
   def initialize(card)
     strong_n = 0
@@ -26,16 +21,13 @@ class StationResult
         when 1
           @time = e.text
       end
-
       strong_n += 1
     }
-
     @trams = []
     card.to_s.scan(/br\/>(\d+:\d+\*?) (.+?)-> (.+?) column_widths[i]
       }
     }
-
     "\n\n#{@name}, #{@time}:\n\n" +
-
     'Zeit'.ljust(column_widths[0]) + ' | ' +
       'Linie'.ljust(column_widths[1]) + ' | ' +
       'Ziel'.ljust(column_widths[2]) + "\n" +
-
     ('-' * column_widths[0]) + '-+-' +
       ('-' * column_widths[1]) + '-+-' +
       ('-' * column_widths[2]) + "\n" +
-
     @trams.collect { |time,tram,direction|
       time.ljust(column_widths[0]) + ' | ' +
         tram.ljust(column_widths[1]) + ' | ' +
@@ -61,12 +49,10 @@ class StationResult
     }.join("\n")
   end
 end
-
 class ClientHandler
   def initialize(socket)
     @socket = socket
     puts "#{address} connected"
-
     Thread.new {
       begin
         handle
@@ -77,7 +63,6 @@ class ClientHandler
       end
     }
   end
-
   def address
     if @socket.peeraddr[0] == 'AF_INET6'
       "[#{@socket.peeraddr[3]}]"
@@ -86,7 +71,6 @@ class ClientHandler
     end +
     ":#{@socket.peeraddr[1]}"
   end
-
   def ask_haltestellenmonitor(station)
     param = { :station => station,
               :action => :check,
@@ -98,7 +82,6 @@ class ClientHandler
     res = Net::HTTP.start('wap.dvbag.de') { |http|
       http.get('/wapVVO/wap-rbl.php?' + param_s)
     }
-
     if res.kind_of? Net::HTTPSuccess
       wml = REXML::Document.new(res.body).root
       card = nil
@@ -109,7 +92,6 @@ class ClientHandler
           card.each_element('p/select/option') { |option|
             stations << option.text
           }
-
           raise MultipleStations.new(stations)
         elsif card.attributes['id'] == 'result'
           StationResult.new(card).to_s
@@ -123,31 +105,27 @@ class ClientHandler
       raise "#{res.class}"
     end
   end
-
   def handle
     @socket.print "Hallo #{address}\n\nHaltestelle: "
     @socket.flush
-
     haltestelle = @socket.gets
     if haltestelle
       haltestelle.strip!
-
       puts "#{address} asks for #{haltestelle.inspect}"
       @socket.puts "Anfrage nach #{haltestelle}..."
-
       @socket.puts ask_haltestellenmonitor(haltestelle)
     end
   end
 end
-
 serv = TCPServer.new('0.0.0.0', 65023)
 while client = serv.accept
   ClientHandler.new(client)
 end
 
- Und dann: telnet localhost 65023 - - [[Kategorie:Ruby]] + + + +{{Rübÿ Spëëd Mëtäl Cödïng}}