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

Joined: 22 Feb 2020 Posts: 398
|
Posted: Sat May 08, 2021 4:13 pm Post subject: |
|
|
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: |
!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: |
!w london, united kingdom
|
otherwise it wont work
TLDR: Stick to using alpha codes for country names
Examples
Code: |
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: |
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
@CrazyCat, yeah i'll change the namespace variables later _________________ ComputerTech |
|
Back to top |
|
 |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Fri May 28, 2021 2:02 am Post subject: |
|
|
Possible to add/show time/date when Weather report was Updated Last? |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Fri May 28, 2021 12:07 pm Post subject: |
|
|
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  _________________ ComputerTech |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Fri May 28, 2021 2:41 pm Post subject: |
|
|
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  _________________ ComputerTech |
|
Back to top |
|
 |
play4free2 Voice

Joined: 23 Nov 2013 Posts: 34
|
Posted: Mon May 31, 2021 8:20 pm Post subject: |
|
|
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 _________________
420-HIGHTIMES IRC Network |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Mon May 31, 2021 9:55 pm Post subject: |
|
|
play4free2, that's a cool suggestion, however i rsther stick with openweathermap
I can however create a seperate version which uses the suggested API  _________________ ComputerTech
Last edited by ComputerTech on Thu Jun 24, 2021 8:00 am; edited 2 times in total |
|
Back to top |
|
 |
creasy Voice
Joined: 05 Mar 2016 Posts: 24
|
Posted: Wed Jun 23, 2021 8:40 am Post subject: |
|
|
Thanks for the script ComputerTech. Is there a possibility to get forecast, too?
Also, shouldn't metric met3 be "kmph" and imperial "mph"? |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Wed Jun 23, 2021 9:11 am Post subject: |
|
|
creasy, Yep! it will use the same API key too!
I'll post here when i release the new version  _________________ ComputerTech |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Wed Sep 01, 2021 6:53 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Fri Oct 08, 2021 12:22 am Post subject: |
|
|
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: |
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: |
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.  _________________ ComputerTech |
|
Back to top |
|
 |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Fri Oct 08, 2021 12:59 am Post subject: |
|
|
[/code]<@USER> !W islamabad
<@Bot> [09Weather] Location: اسا
آباد, فا داراحک
ت اسا
آباد, 44000, پاکستا || Longitutde: 73.0651511 || Latitude: 33.6938118 || Temperature:: 300.84?C || Humidity: 58%
<@Bot> Wind:: 1.37MPH Degree: 211 || Description:: clear sky || Clouds: 0% Code: |
If I search for Pakistani City , It shows ASCII CODES in place of City/Country Name. |
|
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1145 Location: France
|
Posted: Fri Oct 08, 2021 2:21 am Post subject: |
|
|
Need to add &accept-language=en (or whatever you want as language) in the query _________________ Eggdrop community - French IRC network |
|
Back to top |
|
 |
Goga Halfop
Joined: 19 Sep 2020 Posts: 83
|
Posted: Fri Oct 08, 2021 2:30 am Post subject: |
|
|
Code: | <@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? |
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1145 Location: France
|
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 398
|
Posted: Fri Oct 08, 2021 9:51 am Post subject: |
|
|
CrazyCat wrote: | Need to add &accept-language=en (or whatever you want as language) in the query |
Yep, CrazyCat is correct (as usual ), i just checked for your first location, and...
Code: |
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 |
|
Back to top |
|
 |
|