View previous topic :: View next topic |
Author |
Message |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 315
|
Posted: Wed Apr 07, 2021 12:33 am Post subject: CT-Weather |
|
|
So i decided to release a Weather script which uses Openweathermap API Key
Code: |
###########################################################
# 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) "
}
###########################################################
|
Grab a Free API Key from the link in the description, all bug finds and suggestions are more than welcome
and yes i plan to add !w set location and other things tomorrow
but do remember, this version is a beta  _________________ ComputerTech |
|
Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3713 Location: Mint Factory
|
Posted: Wed Apr 07, 2021 3:15 am Post subject: |
|
|
I signed up for a free plan but I keep getting the 401 error, even if the key is correct. Anyway, could you copy/paste the JSON result (it's $data2 variable) of any query to have a look at something? _________________ Once the game is over, the king and the pawn go back in the same box. |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 315
|
Posted: Wed Apr 07, 2021 11:31 am Post subject: |
|
|
Sure
Code: |
{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":6.76,"feels_like":3.07,"temp_min":5.56,"temp_max":8.89,"pressure":1024,"humidity":42},"visibility":10000,"wind":{"speed":6.17,"deg":300},"clouds":{"all":85},"dt":1617808949,"sys":{"type":1,"id":1414,"country":"GB","sunrise":1617772914,"sunset":1617820973},"timezone":3600,"id":2643743,"name":"London","cod":200}
|
If you want, i can PM you my API key
also try this
Code: |
https://api.openweathermap.org/data/2.5/weather?q=london&units=metric&appid=Your-API-Key-Here
|
In your browser  _________________ ComputerTech |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|