Code: Select all
###########################################################
# CT-Weather #
###########################################################
# Author: ComputerTech #
# Email: ComputerTech312@Gmail.com #
# Github: https://github.com/computertech312 #
# Version: 0.1 #
# Release: 06/04/2021 #
###########################################################
# Description: #
# #
# - A Weather script which uses the #
# OpenWeathermap API Key. #
# - https://openweathermap.org/api #
# #
# History: #
# #
# - 0.1: First release. #
# #
###########################################################
# Start of configuration #
##########################
##########################
# Trigger
###
set ctw(trig) "!w"
##########################
# Flags
###
# Owner = n
# Master = m
# Op = o
# Voice = v
# Friend = f
# Everyone = -
##
set ctw(flag) "-"
##########################
# API Key
###
set ctw(api) "Your-API-Key"
##########################
# Output Method
###
# 0 = Notice
# 1 = Privmsg
# 2 = Channel
##
set ctgg(msg) "2"
##########################
# Metric Type
###
# 0 = Metric
# 1 = Imperial
##
set ctw(met) "0"
##########################
# End of configuration #
###########################################################
package require json
package require tls
package require http
bind PUB $ctw(flag) $ctw(trig) weather:call
proc weather:call {nick host hand chan text} {
global ctw
http::register https 443 [list ::tls::socket]
set ctw(location) [join $text ,]
switch -- $ctw(met) {
"0" {set ctw(metr) "metric"
set ctw(met2) "C"
set ctw(met3) "mph"}
"1" {set ctw(metr) "imperial"
set ctw(met2) "F"
set ctw(met3) "kmph"}
}
switch -- $ctw(msg) {
"0" {set ctw(out) "NOTICE $nick"}
"1" {set ctw(out) "PRIVMSG $nick"}
"2" {set ctw(out) "PRIVMSG $chan"}
}
set ctw(url) "http://api.openweathermap.org/data/2.5/weather?q=$ctw(location)&units=$ctw(metr)&appid=$ctw(api)"
set data [http::data [http::geturl "$ctw(url)" -timeout 10000]]
http::cleanup $data
set data2 [::json::json2dict $data]
set basic [dict get $data2 "weather"]
set description [dict get $basic "description"]
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 sys [dict get $data2 "sys"]
set country [dict get $sys "country"]
set name [dict get $data2 "name"]
http::unregister https
putserv "$ctw(out) :\00309\[Weather\]\003 ${name}, $country | ${temp}$ctw(met2) | $description | Humidity: ${humidity}% | Wind: ${speed}$ctw(met3) "
}
###########################################################
and yes i plan to add !w set location and other things tomorrow
but do remember, this version is a beta