egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CT-Weather

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 315

PostPosted: Wed Apr 07, 2021 12:33 am    Post subject: CT-Weather Reply with quote

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 Wink

and yes i plan to add !w set location and other things tomorrow

but do remember, this version is a beta Wink
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3713
Location: Mint Factory

PostPosted: Wed Apr 07, 2021 3:15 am    Post subject: Reply with quote

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
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 315

PostPosted: Wed Apr 07, 2021 11:31 am    Post subject: Reply with quote

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 Smile

also try this
Code:

https://api.openweathermap.org/data/2.5/weather?q=london&units=metric&appid=Your-API-Key-Here

In your browser Razz
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber