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  Next
 
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: 398

PostPosted: Sat May 08, 2021 4:13 pm    Post subject: Reply with quote

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 Smile

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 Smile

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

@CrazyCat, yeah i'll change the namespace variables later
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 83

PostPosted: Fri May 28, 2021 2:02 am    Post subject: Reply with quote

Possible to add/show time/date when Weather report was Updated Last?
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Fri May 28, 2021 12:07 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Fri May 28, 2021 2:41 pm    Post subject: Reply with quote

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 Laughing
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
play4free2
Voice


Joined: 23 Nov 2013
Posts: 34

PostPosted: Mon May 31, 2021 8:20 pm    Post subject: Reply with quote

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


Joined: 22 Feb 2020
Posts: 398

PostPosted: Mon May 31, 2021 9:55 pm    Post subject: Reply with quote

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

I can however create a seperate version which uses the suggested API Razz
_________________
ComputerTech


Last edited by ComputerTech on Thu Jun 24, 2021 8:00 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
creasy
Voice


Joined: 05 Mar 2016
Posts: 24

PostPosted: Wed Jun 23, 2021 8:40 am    Post subject: Reply with quote

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


Joined: 22 Feb 2020
Posts: 398

PostPosted: Wed Jun 23, 2021 9:11 am    Post subject: Reply with quote

creasy, Yep! it will use the same API key too! Very Happy

I'll post here when i release the new version Razz
_________________
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: 398

PostPosted: Wed Sep 01, 2021 6:53 pm    Post subject: Reply with quote

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 Smile
_________________
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: 398

PostPosted: Fri Oct 08, 2021 12:22 am    Post subject: Reply with quote

Sorry for the long wait everyone, here's the release i spoke about, using Geocoding Smile, i've provided a API key, so all you will have to do, is load this script and use the script. Wink
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. Razz
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 83

PostPosted: Fri Oct 08, 2021 12:59 am    Post subject: Reply with quote

[/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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1145
Location: France

PostPosted: Fri Oct 08, 2021 2:21 am    Post subject: Reply with quote

Need to add &accept-language=en (or whatever you want as language) in the query
_________________
Eggdrop community - French IRC network
Back to top
View user's profile Send private message Visit poster's website
Goga
Halfop


Joined: 19 Sep 2020
Posts: 83

PostPosted: Fri Oct 08, 2021 2:30 am    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1145
Location: France

PostPosted: Fri Oct 08, 2021 3:35 am    Post subject: Reply with quote

Probably a bug. It's weird that a script gives correct informations.
_________________
Eggdrop community - French IRC network
Back to top
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 398

PostPosted: Fri Oct 08, 2021 9:51 am    Post subject: Reply with quote

CrazyCat wrote:
Need to add &accept-language=en (or whatever you want as language) in the query

Yep, CrazyCat is correct (as usual Razz), 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. Smile
_________________
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  Next
Page 2 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