Code: Select all
!w los+angeles, United States
Code: Select all
package require json
package require tls
package require http
set ctw(api) "YOUR-API-KEY-HERE"
bind PUB - "!w" weather:call
proc weather:call {nick host hand chan text} {
global ctw
http::register https 443 [list ::tls::socket]
set uargs [http::formatQuery q [lindex [split $text] 0] units=metric appid=$ctw(api)]
set data [http::data [http::geturl "http://api.openweathermap.org/data/2.5/weather?" -query $uargs -timeout 10000]]
http::cleanup $data
http::unregister https
set data2 [::json::json2dict $data]
set name [dict get $data2 "name"]
set sys [dict get $data2 "sys"]
set country [dict get $sys "country"]
set main [dict get $data2 "main"]
set temp [dict get $main "temp"]
set humidity [dict get $main "humidity"]
set wind [dict get $data2 "wind"]
set speed [dict get $wind "speed"]
set current [dict get [lindex [dict get $data2 weather] 0] description]
putserv "PRIVMSG $chan :\[\00309Weather\003\] ${name}, $country | ${temp}$ctw(met2) | ${speed}$ctw(met3) | $current | ${humidity}%"
}
Thanks in advanced