#Experiment #Train times and more ############################### # Start of configuration # ############################### namespace eval batrains { ############################### # Trigger ############################### variable ::trig "!trains" ############################### # Flags # # Owner = n # Master = m # Op = o # Voice = v # Friend = f # Everyone = - ############################### variable ::flag "-" ############################### # API ID # API Key ############################### variable ::api_key "Your-API-Key" variable ::api_id "Your-API-ID" ############################### # Output Method # # 0 = Notice # 1 = Privmsg # 2 = Channel ############################### variable ::msg "2" ############################### # End of configuration # ############################### package require json package require tls package require http bind PUB $::flag $::trig [namespace current]::trains:call proc trains:call {nick host hand chan text} { http::register https 443 [list ::tls::socket] switch -- $::msg { "0" {variable out "NOTICE $nick"} "1" {variable out "PRIVMSG $nick"} "2" {variable out "PRIVMSG $chan"} } variable url "ttps://transportapi.com/v3/uk/train/station/STP///timetable.json?[join $text ,]app_id=$::api_id&app_key=$app_key=$::api_key&calling_at=STE&destination=SUO&station_detail=calling_at&train_status=passenger" variable data [http::data [http::geturl "$url" -timeout 10000]] variable data [http::data [http::geturl "$url" -timeout 10000]] http::cleanup $data http::unregister https variable data2 [::json::json2dict $data] variable tr [dict get $data2 "tr"] if {$tr == "404"} { putserv "PRIVMSG $chan \00304Page not found, be more specific\003" } if {$tr == "200"} { variable date [dict get $data2 "date"] variable time [dict get $data2 "time_of_day"] variable station [dict get $data2 "station_name"] variable oper [dict get $data2 "operator_name"] variable main [dict get $data2 "main"] variable departures [dict get $main "departures"] variable service [dict get $main "service_timetable"] variable id [dict get $data2 "id"] variable pl [dict get $data2 "platform"] variable aim [dict get $data2 "aim_departure_time"] putserv "$out :\[\00309Live Departures\003\] from $station requested at ${date} - ${time}, $oper arriving on ${pl} | Aiming to depart at ${aim} | ${departures} $service" } } } putlog "Trains STP-STE Loaded"