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
 
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: 374

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
Voice


Joined: 19 Sep 2020
Posts: 35

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: 374

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: 374

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: 28

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: 374

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: 374

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: 374

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
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
Page 2 of 2

 
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