This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

CT-Weather

Support & discussion of released scripts, and announcements of new releases.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

|| 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
.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

SpiKe^^ wrote:
|| 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. :roll:
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Code: Select all

#################################
# 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: Select all

<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
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Ver 0.0.3 (+variable-adjusted)

Post by SpiKe^^ »

Just a small code correction...

##################################
### +variable-adjusted Notes ###
# Corrected the usage of [variable] inside procs.
# Corrected the "Metric type" setting explanation.
##################################

Code: Select all

#################################
# CTweather
###
# Version: v0.0.3 (+variable-adjusted)
# Author : ComputerTech
# GitHub : https://GitHub.com/computertech312
###

##################################
###  +variable-adjusted Notes  ###
# Corrected the usage of [variable] inside procs.
# Corrected the "Metric type" setting explanation.
##################################

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 = Imperial
	# 1 = Metric
	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 {
			"0" {set tempy "F" ; set windy "MPH" ; set typex "imperial"}
			"1" {set tempy "C" ; set windy "KPH" ; set typex "metric"}
		}

		set url "https://nominatim.openstreetmap.org/search/"
		set params [::http::formatQuery q $text format jsonv2 ]
		set jsonx [getdata $url $params]
		set name [dict get [lindex $jsonx 0] "display_name"]
		set lati [dict get [lindex $jsonx 0] "lat"]
		set long [dict get [lindex $jsonx 0]  "lon"]

		set url "https://api.openweathermap.org/data/2.5/weather"
		set params [::http::formatQuery lat $lati lon $long appid $api units $typex]
		set jsonx [getdata $url $params]
		set temp [dict get [dict get $jsonx "main"] "temp"]
		set speed [dict get [dict get $jsonx "wind"] "speed"]
		set degre [dict get [dict get $jsonx "wind"] "deg"]
		set humid [dict get [dict get $jsonx "main"] "humidity"]
		set cover [dict get [dict get $jsonx "clouds"] "all"]
		set 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"

		set data [http::data [http::geturl "$url?$params" -timeout 10000]]
		::http::cleanup $data
		set jsonx [json::json2dict $data]
		return $jsonx
	}
}

Last edited by SpiKe^^ on Tue Jan 25, 2022 12:52 am, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Cheers for the code fixes Spike^^ !! :D
ComputerTech
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i was wondering why UTF-8 isnt working for this tcl
for example :

(+Simo) : !w ryadh

(@Hawk) : [Weather] Location: الرياض, مديرية تريم, محافظة حضرموت, اليمن || Longitutde: 49.224962 || Latitude: 16.1146368 || Temperature:: 13.54C

(@Hawk) : Humidity: 44% Wind:: 1.26KPH Degree: 26 || Description:: clear sky || Clouds: 1%
UTF-8 works for me for other tcls like youtube so that cant be it
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

I am currently working on version 0.0.4 of this script, which will boast a more streamlined codebase and improved functionality. Specifically, it will incorporate the following features:

- Location saving for enhanced convenience.
- Usage throttling to optimize performance and efficiency.
- Option for users to choose either Metric or Imperial units, according to their preferences.
- Forecast option for up to X number of days, to provide extended information.

I am open to additional feature requests, but for now, these are the key upgrades that I am focused on implementing. 8)
ComputerTech
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

ComputerTech wrote: ...
- Option for users to choose either Metric or Imperial units, according to their preferences.
...

I am open to additional feature requests, but for now, these are the key upgrades that I am focused on implementing. 8)

"either" Metric or Imperial...

How about a third option? Both. :)

Maybe so that the display is like: 77F (25C)

You would have to play with it, to see if it looks too cluttered. To see if you can get it so that it is ok to the eye.

You asked, and this came to mind. :) It's just a thought. No big deal.



p.s.
Another thought came to mind:
How about ALWAYS both, just the option is to pick which one comes first?
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
B
Bosco
Voice
Posts: 9
Joined: Mon Oct 31, 2022 10:57 pm

Post by Bosco »

Image

u mean like this ....
User avatar
FmX
Voice
Posts: 39
Joined: Wed Dec 06, 2006 12:42 pm

Post by FmX »

Hi. Script stop working.
Error i see is this:

Code: Select all

[23:09:53] <ATAS> [20:09:53] https://nominatim.openstreetmap.org/search/?q=%D1%81%D0%BE%D1%84%D0%B8%D1%8F%20&format=jsonv2
[23:09:53] <ATAS> [20:09:54] Tcl error [::CTweather::current:weather]: missing value to go with key
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

FmX wrote:Hi. Script stop working.
Error i see is this:

Code: Select all

[23:09:53] <ATAS> [20:09:53] https://nominatim.openstreetmap.org/search/?q=%D1%81%D0%BE%D1%84%D0%B8%D1%8F%20&format=jsonv2
[23:09:53] <ATAS> [20:09:54] Tcl error [::CTweather::current:weather]: missing value to go with key
Just try the url in a browser and you'll have a self-explanatory message:
File not found: API no longer accessible via this URL

Using the URL /search/ and /reverse/ (with slashes) is no longer supported. Please use URLs as given in the documentation.

Examples how to change the URL:

You use: https://nominatim.openstreetmap.org/search/?q=Berlin
Change to: https://nominatim.openstreetmap.org/search?q=Berlin

You use: https://nominatim.openstreetmap.org/sea ... xas/Huston
Change to: https://nominatim.openstreetmap.org/search?q=Huston, Texas, US

See github issue #3134 for more details.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

I'm working on a new updated/working version, will hopefully release today/tomorrow. 8)
ComputerTech
User avatar
FmX
Voice
Posts: 39
Joined: Wed Dec 06, 2006 12:42 pm

Post by FmX »

I thought the problem was in the script something. I waved / and went again. thanks
H
Henkie2
Voice
Posts: 35
Joined: Fri Sep 25, 2015 2:55 pm

Re:

Post by Henkie2 »

ComputerTech wrote: Tue Oct 03, 2023 9:23 am I'm working on a new updated/working version, will hopefully release today/tomorrow. 8)
Hi any news on updated version? Or how can i edit the correct lines? Thx
Post Reply