Last active
March 28, 2022 08:20
-
-
Save s3krit/9e09673b0411f7a924227fb7d4f8667f to your computer and use it in GitHub Desktop.
Little script to pull info about the ICE train you're currently on
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'json' | |
require 'net/http' | |
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE | |
status_url = 'https://portal.imice.de/api1/rs/status' | |
trip_url = 'https://portal.imice.de/api1/rs/tripInfo/trip' | |
begin | |
status = JSON.parse(Net::HTTP.get(URI(status_url))) | |
trip = JSON.parse(Net::HTTP.get(URI(trip_url))) | |
rescue => e | |
puts e | |
return | |
end | |
next_station = trip['trip']['stops'].select { |s| s['station']['evaNr'] == trip['trip']['stopInfo']['actualNext'] }[0] | |
final_station = trip['trip']['stops'].select { |s| s['station']['evaNr'] == trip['trip']['stopInfo']['finalStationEvaNr'] }[0] | |
puts <<~EOT | |
Train: #{trip['trip']['trainType']} #{trip['trip']['vzn']} | |
Speed: #{status['speed']} km/h | |
Next stop: #{next_station['station']['name']} - #{Time.at(next_station['timetable']['actualArrivalTime'] / 1000).strftime('%H:%M')} | |
Final stop: #{final_station['station']['name']} - #{Time.at(final_station['timetable']['actualArrivalTime'] / 1000).strftime('%H:%M')} | |
Internet status: #{status['internet']} | |
Server time: #{Time.at(status['serverTime'] / 1000).strftime('%H:%M')} | |
EOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment