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

Post by ComputerTech »

Okay so, i fixed the problems, however due to openweathermap only prefering alpha codes. this is how to use it


For a location specified with the country name only with 2 letters can either have a , at the end of the city name or not, up to you, doesn't matter.

Code: Select all

!w london, GB  or !london GB
If however you want to specify the full country name like United Kingdom, you will need to add a , at the end of the city name like.

Code: Select all

!w london, united kingdom
otherwise it wont work

TLDR: Stick to using alpha codes for country names :)

Examples

Code: Select all

 ComputerTech !w london gb
 Alpha [Weather] London, GB | 15.14C | 4.63mph | few clouds | 67%
 ComputerTech !w london, gb
 Alpha [Weather] London, GB | 15.14C | 4.63mph | few clouds | 67%
 ComputerTech !w london Great britain
 Alpha Page not found, be more specific
 ComputerTech !w london, Great britain
 Alpha [Weather] London, GB | 15.14C | 4.63mph | few clouds | 67%
Code

Code: Select all

namespace eval ctweather {
   ##########################
   # Start of configuration #
   ##########################

   ##########################
   # Trigger
   ###
   variable ::trig "!w"


   ##########################
   # Flags
   ###
   # Owner     = n
   # Master    = m
   # Op        = o
   # Voice     = v
   # Friend    = f
   # Everyone  = -
   ##
   variable ::flag "-"


   ##########################
   # API Key
   ###
   variable ::api "8c2a600d5d63d7fb13432fd58dcc419b"

   variable ::met "0"

   package require json
   package require tls
   package require http

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

   proc weather:call {nick host hand chan text} {
      http::register https 443 [list ::tls::socket]
      switch -- $::met {
         "0" {variable metr "metric"
            variable met2 "C"
            variable met3 "mph"}
         "1" {variable metr "imperial"
            variable met2 "F"
            variable met3 "kmph"}
      }

if { [string length [lindex [split $text] end]] == 2 } {

		set text [regsub { ([^ ]+)$} $text {,\1}]
}
variable url "http://api.openweathermap.org/data/2.5/weather"
variable params [::http::formatQuery q $text units metric APPID $::api]
putlog "$url?$params"
variable data [http::data [http::geturl "$url?$params" -timeout 10000]]
      http::cleanup $data
      http::unregister https
      variable data2 [::json::json2dict $data]
      variable cod [dict get $data2 "cod"]

      if {$cod == "404"} {
         putserv "PRIVMSG $chan \00304Page not found, be more specific\003"
      }
      if {$cod == "200"} {
         variable name [dict get $data2 "name"]
         variable sys [dict get $data2 "sys"]
         variable country [dict get $sys "country"]
         variable main [dict get $data2 "main"]
         variable temp [dict get $main "temp"]
         variable humidity [dict get $main "humidity"]
         variable wind [dict get $data2 "wind"]
         variable speed [dict get $wind "speed"]
         variable weather2 [dict get $data2 "weather"]
         variable current [dict get [lindex [dict get $data2 weather] 0] description]
         variable name   [encoding convertfrom utf-8 $name]
         putserv "PRIVMSG $chan :\[\00309Weather\003\] ${name}, $country | ${temp}$met2 | ${speed}$met3 | $current | ${humidity}%"
      }
   }
}
Enjoy, and reply with any bug reports :)

Sidenote: will try add default location setting as soon as i can :wink:

@CrazyCat, yeah i'll change the namespace variables later
ComputerTech
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

Possible to add/show time/date when Weather report was Updated Last?
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Apparently it's available but only XML and not json according to

https://openweathermap.org/current

so i sent them a email asking if its possible for json type to have the "lastupdate" option :wink:
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Okay so they responded and said it's only available in XML format, so i'll have to create a XML version of the script :lol:
ComputerTech
User avatar
play4free2
Voice
Posts: 34
Joined: Sat Nov 23, 2013 1:42 am
Contact:

Post by play4free2 »

ComputerTech

You might want to check out this site it uses json, gives you 1,000,000 calls per month, both Metric and Imperial temps. etc. and also gives you the last updated time and more. https://www.weatherapi.com/

Just a suggestion,
play4free2
Image
420-HIGHTIMES IRC Network
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

play4free2, that's a cool suggestion, however i rsther stick with openweathermap

I can however create a seperate version which uses the suggested API :P
Last edited by ComputerTech on Thu Jun 24, 2021 8:00 am, edited 2 times in total.
ComputerTech
c
creasy
Voice
Posts: 24
Joined: Sat Mar 05, 2016 4:21 am

Post by creasy »

Thanks for the script ComputerTech. Is there a possibility to get forecast, too?
Also, shouldn't metric met3 be "kmph" and imperial "mph"?
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

creasy, Yep! it will use the same API key too! :D

I'll post here when i release the new version :P
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Planning on releasing a new version of this script the upcoming nearby future, Here's the new features.

[1] Option to use PositionStack API to improve accuracy.
[2] User's will be able to save their location with !w set.
[3] Ability to view the forecast.
[4] Some bugs and suggestions suggested by CrazyCat.

That's all that will be added/changed for now, if you have a request, please post below :)
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Sorry for the long wait everyone, here's the release i spoke about, using Geocoding :), i've provided a API key, so all you will have to do, is load this script and use the script. ;)

Code: Select all

namespace eval CTweather {
	## Trigger.
	variable trig "!w"

	## Flags.
	variable flag "of|of"

	#####

	variable api "8c2a600d5d63d7fb13432fd58dcc419b"

	variable type "imperial"

	package require json
	package require tls
	package require http

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

	proc mainproc {nick host hand chan text} {
		variable api ;variable type
		::http::register https 443 [list ::tls::socket]
		variable url "https://nominatim.openstreetmap.org/search/"
		variable params [::http::formatQuery q $text format jsonv2]
        putlog "$url?$params"
		variable data [http::data [http::geturl "$url?$params" -timeout 10000]]
		variable data2 [json::json2dict $data]
		variable name [dict get [lindex $data2 0] "display_name"]
		variable lati [dict get [lindex $data2 0] "lat"]
		variable long [dict get [lindex $data2 0]  "lon"]
		variable url2 "https://api.openweathermap.org/data/2.5/weather"
        variable params2 [::http::formatQuery q [lindex [split $text] 0] lat $lati lon $long appid $api]
        putlog "$url2?$params2"
		variable bata [http::data [http::geturl "$url2?$params2" -timeout 10000]]
		variable zata [::json::json2dict $bata]
		variable temp [dict get [dict get $zata "main"] "temp"]
		variable speed [dict get [dict get $zata "wind"] "speed"]
		variable degre [dict get [dict get $zata "wind"] "deg"]
		variable humid [dict get [dict get $zata "main"] "humidity"]
		variable cover [dict get [dict get $zata "clouds"] "all"]
		variable desc [dict get [lindex [dict get $zata weather] 0] "description"]
		variable sign [encoding convertfrom "utf-8" "?"]
		switch -exact $type {
			"metric" {variable type2 "${sign}F"}
			"imperial" {variable type2 "${sign}C"}
		}
		putserv "PRIVMSG $chan :\[\00309Weather\003\] Location: $name || Longitutde: $long  || Latitude: $lati || Temperature:: ${temp}$type2 || Humidity: ${humid}% "
		putserv "PRIVMSG $chan :Wind:: ${speed}MPH  Degree: $degre || Description:: $desc  || Clouds: ${cover}%"
	}
}
Example of usage:

Code: Select all

18<CX18> [09Weather] Location: Belfast, County Antrim, Northern Ireland, BT1 5GS, United Kingdom || Longitutde: -5.9302761  || Latitude: 54.5964411 || Temperature:: 288.24?C || Humidity: 99% 
18<CX18> Wind:: 2.57MPH  Degree: 180 || Description:: moderate rain  || Clouds: 90%
This is a very rough piece of code, but feedback is appreciated as always. :P
ComputerTech
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

[/code]<@USER> !W islamabad
<@Bot> [09Weather] Location: اسÙ&#132;اÙ&#133; آباد, Ù&#136;فاÙ&#130;Û&#140; داراÙ&#132;Ø­Ú©Ù&#136;Ù&#133;ت اسÙ&#132;اÙ&#133; آباد, 44000, پاکستاÙ&#134; || Longitutde: 73.0651511 || Latitude: 33.6938118 || Temperature:: 300.84?C || Humidity: 58%
<@Bot> Wind:: 1.37MPH Degree: 211 || Description:: clear sky || Clouds: 0%

Code: Select all


If I search for Pakistani City , It shows ASCII CODES in place of City/Country Name.
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Need to add &accept-language=en (or whatever you want as language) in the query
G
Goga
Halfop
Posts: 84
Joined: Sat Sep 19, 2020 2:12 am

Post by Goga »

Code: Select all

 <@USER> !W Saba
<@BOT> [09Weather] Location: Sabah, Malaysia || Longitutde: 117.0326392  || Latitude: 5.4257359 || Temperature:: 293.9?C || Humidity: 98% 
<@BOT> Wind:: 1.11MPH  Degree: 167 || Description:: overcast clouds  || Clouds: 93%

Why showing this Correctly?
User avatar
CrazyCat
Revered One
Posts: 1301
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Probably a bug. It's weird that a script gives correct informations.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

CrazyCat wrote:Need to add &accept-language=en (or whatever you want as language) in the query
Yep, CrazyCat is correct (as usual :P), i just checked for your first location, and...

Code: Select all

https://nominatim.openstreetmap.org/search/islamabad?format=jsonv2
For the GeoCoding API, it seems to show your latitude and longitude perfectly, so you need to change your language on the weather API accordingly. :)
ComputerTech
Post Reply