Gathers results from wunderground.com and returns them to irc.
Triggers:
Syntax:
ScreenShot:
Loading:
See the setup at the top of the script.
##############################################################################################
## ## wunderground.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
##############################################################################################
## To use this script you must set channel flag +weather (ie .chanset #chan +weather) ##
##############################################################################################
##############################################################################################
## ## Start Setup. ## ##
##############################################################################################
namespace eval wunderground {
## Edit logo to change the logo displayed at the start of the line ## ##
variable logo "\017\00304\002W\00304u\00307n\00308d\00311e\00312r\00304g\00307r\00308o\00311u\00312n\00304d\017"
## Edit textf to change the color/state of the text shown ## ##
variable textf "\017\00304"
## Edit tagf to change the color/state of the Tags: ## ##
variable tagf "\017\002"
## Edit weatherline, line1, line2, line3, line4 to change what is displayed ## ##
## weatherline is for the !weather trigger and line1-4 are for !forecast ## ##
## Valid items are: location weatherstation conditions tempf tempc tempfc feelsf ## ##
## feelsc feelsfc windgust windspeed winddirection sunset sunrise moon ## ##
## day1 day2 day3 day4 day5 day6 day7 day8 day9 day10 ## ##
## Do not remove any variables here! Just change them to "" to suppress display ## ##
variable line1 "location weatherstation conditions tempfc feelsfc windspeed winddirection windgust sunset sunrise moon"
variable line2 "day1 day2 day3"
variable line3 "day4 day5"
variable line4 ""
variable weatherline "location weatherstation conditions tempfc feelsfc windspeed winddirection windgust sunset sunrise moon"
## Edit cmdchar to change the !trigger used to for this script ## ##
variable cmdchar "!"
##############################################################################################
## ## End Setup. ## ##
##############################################################################################
setudef flag weather
bind pub -|- [string trimleft $wunderground::cmdchar]weather wunderground::main
bind pub -|- [string trimleft $wunderground::cmdchar]forecast wunderground::main
}
proc wunderground::main {nick host hand chan text} {
if {[lsearch -exact [channel info $chan] +weather] != -1} {
set search [strip $text]; set command [string trimleft $::lastbind $wunderground::cmdchar]
set div ""; set moon ""; set sunset ""; set sunrise ""; set windspeed ""; set div ""
set winddirection ""; set location ""; set weatherstation ""; set temperature ""; set tempfc ""
set conditions ""; set feelslike ""; set feelsf ""; set feelsc ""; set city ""; set day ""
set details ""; set forc ""; set count 1; set tempf ""; set state_name ""; set tempc ""
set day1 ""; set day2 ""; set day3 ""; set day4 ""; set day5 ""; set state_name ""
set day6 ""; set day7 ""; set day8 ""; set day9 ""; set day10 ""; set windgust ""; set feelsfc ""
set wundergroundurl "/cgi-bin/findweather/hdfForecast?query=[urlencode $search]"
set wundergroundsite "www.wunderground.com"
if {[catch {set wundergroundsock [socket -async $wundergroundsite 80]} sockerr]} {
return 0
} else {
puts $wundergroundsock "GET $wundergroundurl HTTP/1.0"
puts $wundergroundsock "Host: $wundergroundsite"
puts $wundergroundsock "User-Agent: Opera 9.6"
puts $wundergroundsock ""
flush $wundergroundsock
while {![eof $wundergroundsock]} {
set wundergroundvar " [gets $wundergroundsock] "
regexp -nocase {"(current)_observation":} $wundergroundvar match div
regexp -nocase {"(forecast)":} $wundergroundvar match div
regexp -nocase {"(astronomy)":} $wundergroundvar match div
if {[regexp -nocase {"city":"([^"]*)} $wundergroundvar match city]} {
if {$city == "null"} {
set city ""
}
} elseif {[regexp -nocase {"state_name":"([^"]*)} $wundergroundvar match state_name]} {
if {$state_name == "null"} {
set state_name ""
}
set location "${wunderground::tagf}Location: ${wunderground::textf}${city}, $state_name"
} elseif {[regexp -nocase {"name":"([^"]*)} $wundergroundvar match weatherstation]} {
set weatherstation "${wunderground::tagf}Station: ${wunderground::textf}${weatherstation}"
} elseif {$forc == "" && [regexp -nocase {class="wx-unit"> °(.*?)<\/span>} $wundergroundvar match forc]} {
} elseif {[regexp -nocase {"condition":"([^"]*)} $wundergroundvar match conditions]} {
set conditions "${wunderground::tagf}Conditions: ${wunderground::textf}${conditions}"
} elseif {$div == "current" && [regexp -nocase {"temperature":\s([^\,]*)} $wundergroundvar match temperature]} {
set tempf "${wunderground::tagf}Temperature: ${wunderground::textf}[forc ${temperature} $forc F]ºF"
set tempc "${wunderground::tagf}Temperature: ${wunderground::textf}[forc ${temperature} $forc C]ºC"
set tempfc "${wunderground::tagf}Temperature: ${wunderground::textf}[forc ${temperature} $forc F]ºF/[forc ${temperature} $forc C]ºC"
} elseif {$div == "current" && [regexp -nocase {"feelslike":\s([^\,]*)} $wundergroundvar match feelslike]} {
set feelsf "${wunderground::tagf}Feels Like: ${wunderground::textf}[forc ${feelslike} $forc F]ºF"
set feelsc "${wunderground::tagf}Feels Like: ${wunderground::textf}[forc ${feelslike} $forc C]ºC"
set feelsfc "${wunderground::tagf}Feels Like: ${wunderground::textf}[forc ${feelslike} $forc F]ºF/[forc ${feelslike} $forc C]ºC"
} elseif {$div == "current" && [regexp -nocase {"wind_speed":\s?([^\,]*)} $wundergroundvar match windspeed]} {
set windspeed "${wunderground::tagf}Wind speed: ${wunderground::textf}${windspeed}"
} elseif {$div == "current" && [regexp -nocase {"wind_gust_speed":\s?([^\,]*)} $wundergroundvar match windgust]} {
set windgust "${wunderground::tagf}Wind gust: ${wunderground::textf}${windgust}"
} elseif {[regexp -nocase {"wind_dir":"([^"]*)} $wundergroundvar match winddirection]} {
set winddirection "${wunderground::tagf}Wind Direction: ${wunderground::textf}${winddirection}"
} elseif {[regexp -nocase {id="cc-sun-rise">(.*?)</span>\s?<span class="ampm">(.*?)</span>} $wundergroundvar match sunrise ampm]} {
set sunrise "${wunderground::tagf}Sunrise: ${wunderground::textf}${sunrise}${ampm}"
} elseif {[regexp -nocase {id="cc-sun-set">(.*?)</span> <span class="ampm">(.*?)</span>} $wundergroundvar match sunset ampm]} {
set sunset "${wunderground::tagf}Sunset: ${wunderground::textf}${sunset}${ampm}"
} elseif {[regexp -nocase {id="cc-moon-phase".*">(.+?)<\/span>} $wundergroundvar match moon]} {
set moon "${wunderground::tagf}Moon: ${wunderground::textf}${moon}"
} elseif {$div == "forecast" && $command == "weather"} {
msg $chan $wunderground::logo ${wunderground::textf} [subst [regsub -all -nocase {(\S+)} $wunderground::weatherline {$\1}]]
close $wundergroundsock
return 0
} elseif {[regexp -nocase {<div\sclass="fctDayDate">(.+)\,} $wundergroundvar match day]} {
set day "${wunderground::tagf}${day}"
} elseif {[string match "forecast" $div]} {
if {[regexp -nocase {"weekday_short":\s?"([^"]*)} $wundergroundvar match day]} {
set day "${wunderground::tagf}${day}:->"
} elseif {[regexp -nocase {"high":\s([^\,]*)} $wundergroundvar match high]} {
set high "${wunderground::tagf}High:${wunderground::textf}[forc $high $forc F]ºF/[forc $high $forc C]ºC"
} elseif {[regexp -nocase {"low":\s([^\,]*)} $wundergroundvar match low]} {
set low "${wunderground::tagf}low:${wunderground::textf}[forc $low $forc F]ºF/[forc $low $forc C]ºC"
} elseif {[regexp -nocase {"condition":\s?"([^"]*)} $wundergroundvar match condition]} {
set condition "${wunderground::tagf}Cond:${wunderground::textf}${condition}"
} elseif {[regexp -nocase {"day":\s?\{} $wundergroundvar]} {
set day${count} "$day $high $low $condition"
incr count
}
} elseif {$div == "astronomy"} {
if {$wunderground::line1 != ""} {
msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line1 {$\1}]]
}
if {$wunderground::line2 != ""} {
msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line2 {$\1}]]
}
if {$wunderground::line3 != ""} {
msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line3 {$\1}]]
}
if {$wunderground::line4 != ""} {
msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line4 {$\1}]]
}
close $wundergroundsock
return 0
}
}
}
}
}
proc wunderground::forc {value fc forc} {
if {[string equal -nocase $fc $forc]} {
return $value
} elseif {[string equal -nocase "f" $fc]} {
if {[expr {(($value - 32) * 5)} == 0]} { return 0 }
return [format "%.1f" [expr {(($value - 32) * 5) / 9}]]
} elseif {[string equal -nocase "c" $fc]} {
if {$value == 0} { return 32 }
return [format "%.1f" [expr {(($value * 9) / 5) + 32}]]
}
}
proc wunderground::striphtml {string} {
return [string map {" \" < < &rt; >} [regsub -all {(<[^<^>]*>)} $string ""]]
}
proc wunderground::urlencode {string} {
regsub -all {^\{|\}$} $string "" string
return [subst [regsub -nocase -all {([^a-z0-9\+])} $string {%[format %x [scan "\\&" %c]]}]]
}
proc wunderground::strip {text} {
regsub -all {\002|\031|\015|\037|\017|\003(\d{1,2})?(,\d{1,2})?} $text "" text
return $text
}
proc wunderground::msg {chan logo textf text} {
set text [textsplit $text 50]
set counter 0
while {$counter <= [llength $text]} {
if {[lindex $text $counter] != ""} {
putserv "PRIVMSG $chan :${logo} ${textf}[string map {\\\" \"} [lindex $text $counter]]"
}
incr counter
}
}
proc wunderground::textsplit {text limit} {
set text [split $text " "]
set tokens [llength $text]
set start 0
set return ""
while {[llength [lrange $text $start $tokens]] > $limit} {
incr tokens -1
if {[llength [lrange $text $start $tokens]] <= $limit} {
lappend return [join [lrange $text $start $tokens]]
set start [expr $tokens + 1]
set tokens [llength $text]
}
}
lappend return [join [lrange $text $start $tokens]]
return $return
}
putlog "\002*Loaded* \00304\002W\00304u\00307n\00308d\00311e\00312r\00304g\00307r\00308o\00311u\00312n\00304d\017 \002by \
Ford_Lawnmower irc.GeekShed.net #Script-Help"
[» Sat Aug 16 | 03:23:58 pm «] Wunderground Location: Adel, Georgia Station: Adel, Georgia Conditions: Mostly Cloudy Temperature: ºF/ºC Feels Like: ºF/ºC Wind speed: 3.5 Wind Direction: NW Wind gust: 7.2 Sunset: 8:14PM Sunrise: 6:59AM
the tcl weather isnt working like it should be
the above is what i got when i type !weather zip-code
i use eggdrop1.6.21
hey, a few minor issues for me..
1) it prints out Wind speed: xx (but doesn't say in which unit) (mph/kph/ m/s)
2) time is shown in 12 hour time. (am/pm).
3) Wednesday Temp: 3º|3º C Cond: IIOvercast. Thursday Temp: 5º|4º C Cond: IIChance of Rain. (same as play4free2 has)
it would be nice to be able to configure in which unit it should display windspeed
and also to be able to configure 24 hour time format.
and to get rid of the || after each Cond:
anyways, thanks for making the scripts. :)
@FordLawnmower great script, I just started using TCL scripts on an eggy I setup to replace my old mIRC bot. I think most of the addons are yours. Anyhow the only issue I see with this one is it doesn't show "location or weatherstation" anymore. Also on !forecast I get 2 orange square boxes in between Cond: and Partly Cloudy (same color as the Partly Cloudy). I can't see them in you screen shot of the script.
Hi. I'd like the script to return metric values.
It seems like when you point your browser to wunderground.com it detects this and shows temperature in C and wind speed in km/h.
I've poked around a little in your script but couldn't find any useragent or url setting for this.
I know you can force temperature to C but that's done through getting the value in F and then mathematically converting it in the script.
Wouldn't it be better to fetch the "correct" values to begin with?
I'm very grateful for any tips!
And thanks for a otherwise great script!
When I load your script then .rehash the bot it crashes and shows me this
I removed your weather script and bot works just fine, so it it has to be something in your script :(
There is no command L in my script. Infact, I don't use UPPER case letters at all in tcl.
So , if this is coming from this script then it must be caused by a #comment being parsed.
My guess is that you didn't completely copy the code and you have a partial line , causing it to read a comment.
This problem can also be caused by using a text editor that adds characters when you click save.
Try starting over and copying the code again. Review the code to make sure it's all there before you try to load it into the eggdrop.
What text editor are you using ?
yup broken here too unfortunatly