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
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 693
Location: Tennessee, USA

PostPosted: Fri Oct 08, 2021 11:56 am    Post subject: Reply with quote

Quote:
|| Temperature:: 293.9?C ||
That's odd, very hot there???
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 385

PostPosted: Fri Oct 08, 2021 2:54 pm    Post subject: Reply with quote

SpiKe^^ wrote:
Quote:
|| Temperature:: 293.9?C ||
That's odd, very hot there???

lol, good job spotting that out Spike^^

The code seems back to front, i'll go fix this later. Rolling Eyes
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 385

PostPosted: Fri Oct 08, 2021 8:00 pm    Post subject: Reply with quote

Code:

#################################
# CTweather
###
# Version: v0.0.3
# Author : ComputerTech
# GitHub : https://GitHub.com/computertech312
###
namespace eval CTweather {
   ## Triggers.
   # Current weather.
   variable trig "!w"
   ##

   ## Flags.
   # n = Owner.
   # m = master
   # o = Op.
   # h = Halfop.
   # v = Voice.
   # f = Friend.
   # - = Nothing.
   variable flag "-|-"
   ##

   ## OpenWeatherMap API Key.
   variable api "8c2a600d5d63d7fb13432fd58dcc419b"

   ## Metric type.
   # 0 = Metric
   # 1 = Imperial
   variable type "0"

   ###

   package require json
   package require tls
   package require http

   bind PUB $flag $trig [namespace current]::current:weather

   proc current:weather {nick host hand chan text} {
      variable api ; variable type
      if {![llength [split $text]]} {
         putserv "privmsg $chan :Syntax: !w \[zip code | Location \]"
         return 0
      }
      switch -exact $type {
         "1" {variable tempy "C" ; variable windy "KPH" ; variable typex "metric"}
         "0" {variable tempy "F" ; variable windy "MPH" ; variable typex "imperial"}
      }
      variable url "https://nominatim.openstreetmap.org/search/"
      variable params [::http::formatQuery q $text format jsonv2 ]
      variable jsonx [getdata $url $params]
      variable name [dict get [lindex $jsonx 0] "display_name"]
      variable lati [dict get [lindex $jsonx 0] "lat"]
      variable long [dict get [lindex $jsonx 0]  "lon"]
      variable url "https://api.openweathermap.org/data/2.5/weather"
      variable params [::http::formatQuery lat $lati lon $long appid $api units $typex]
      variable jsonx [getdata $url $params]
      variable temp [dict get [dict get $jsonx "main"] "temp"]
      variable speed [dict get [dict get $jsonx "wind"] "speed"]
      variable degre [dict get [dict get $jsonx "wind"] "deg"]
      variable humid [dict get [dict get $jsonx "main"] "humidity"]
      variable cover [dict get [dict get $jsonx "clouds"] "all"]
      variable desc [dict get [lindex [dict get $jsonx weather] 0] "description"]
      putserv "PRIVMSG $chan :\[\00309Weather\003\] Location: $name || Longitutde: $long  || Latitude: $lati || Temperature:: ${temp}$tempy"
      putserv "PRIVMSG $chan :Humidity: ${humid}% Wind:: ${speed}$windy  Degree: $degre || Description:: $desc  || Clouds: ${cover}%"
   }

   proc getdata {url params} {
      ::http::register https 443 [list ::tls::socket]
      ::http::config -useragent "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0"
      putlog "$url?$params"
      variable data [http::data [http::geturl "$url?$params" -timeout 10000]]
      ::http::cleanup $data
      variable jsonx [json::json2dict $data]
      return $jsonx
   }
}


Results:
Code:

<ComputerTech> !w london uk
<CX> [Weather] Location: London, Greater London, England, United Kingdom || Longitutde: -0.1276474  || Latitude: 51.5073219 || Temperature:: 51.94F
<CX> Humidity: 93% Wind:: 3.44MPH  Degree: 110 || Description:: haze  || Clouds: 25%

_________________
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
Goto page Previous  1, 2, 3
Page 3 of 3

 
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