weather.disabled (13176B)
1 $::maintype sendUid $::sock($::cs(netname)) "W" "weather" "services." "services." 57 "Weather Services" 2 foreach {chan is} [nda get "weather/regchan"] { 3 if {1!=$is} {continue} 4 $::maintype putjoin $::sock($::cs(netname)) 57 [::base64::decode [string map {[ /} $chan]] [nda get "regchan/$chan/ts"] 5 tnda set "channels/$chan/ts" [nda get "regchan/$chan/$::netname($::sock($::cs(netname)))/ts"] 6 } 7 bind $::sock($::cs(netname)) request "w" "-" weatherjoin 8 bind $::sock($::cs(netname)) request "weather" "-" weatherjoin 9 10 proc weatherjoin {chan msg} { 11 set ndacname [string map {/ [} [::base64::encode [string tolower $chan]]] 12 $::maintype putjoin $::sock($::cs(netname)) 57 $chan [nda get "regchan/$ndacname/ts"] 13 nda set "weather/regchan/$ndacname" 1 14 } 15 16 ############################################################################################## 17 ## ## wunderground.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ## 18 ############################################################################################## 19 ## To use this script you must set channel flag +weather (ie .chanset #chan +weather) ## 20 ############################################################################################## 21 ############################################################################################## 22 ## ## Start Setup. ## ## 23 ############################################################################################## 24 namespace eval wunderground { 25 ## Edit logo to change the logo displayed at the start of the line ## ## 26 variable logo "\017\00304\002W\00304u\00307n\00308d\00311e\00312r\00304g\00307r\00308o\00311u\00312n\00304d\017" 27 ## Edit textf to change the color/state of the text shown ## ## 28 variable textf "\017" 29 ## Edit tagf to change the color/state of the Tags: ## ## 30 variable tagf "\017\002" 31 ## Edit weatherline, line1, line2, line3, line4 to change what is displayed ## ## 32 ## weatherline is for the !weather trigger and line1-4 are for !forecast ## ## 33 ## Valid items are: location weatherstation conditions tempf tempc tempfc feelsf ## ## 34 ## feelsc feelsfc windgust windspeed winddirection sunset sunrise moon ## ## 35 ## day1 day2 day3 day4 day5 day6 day7 day8 day9 day10 ## ## 36 ## Do not remove any variables here! Just change them to "" to suppress display ## ## 37 variable line1 "location weatherstation conditions tempfc feelsfc windspeed winddirection windgust sunset sunrise moon" 38 variable line3 "" 39 variable line2 "day1 day2 day3 day4 day5 day6 day7 day8 day9 day10" 40 variable line4 "" 41 variable weatherline "location weatherstation conditions tempfc feelsfc windspeed winddirection windgust sunset sunrise moon day1 day2 day3" 42 ## Edit cmdchar to change the !trigger used to for this script ## ## 43 variable cmdchar "!" 44 ############################################################################################## 45 ## ## End Setup. ## ## 46 ############################################################################################## 47 bind $::sock($::cs(netname)) pub "-" [string trimleft $wunderground::cmdchar]weather wunderground::tclservwe 48 bind $::sock($::cs(netname)) pub "-" [string trimleft $wunderground::cmdchar]wz wunderground::tclservwe 49 bind $::sock($::cs(netname)) pub "-" [string trimleft $wunderground::cmdchar]forecast wunderground::tclservfc 50 } 51 52 proc wunderground::tclservwe {cname msg} { 53 set nick [tnda get "nick/$::netname($::sock($::cs(netname)))/[lindex $msg 0 0]"] 54 set host "[tnda get "ident/[lindex $msg 0 0]"]@[tnda get "vhost/$::netname($::sock($::cs(netname)))/[lindex $msg 0 0]"]" 55 set comd "weather" 56 set hand "" 57 set text [join [lindex $msg 1] " "] 58 wunderground::main $comd $nick $host $hand $cname $text 59 } 60 61 proc wunderground::tclservfc {cname msg} { 62 set nick [tnda get "nick/$::netname($::sock($::cs(netname)))/[lindex $msg 0 0]"] 63 set host "[tnda get "ident/[lindex $msg 0 0]"]@[tnda get "vhost/$::netname($::sock($::cs(netname)))/[lindex $msg 0 0]"]" 64 set comd "forecast" 65 set hand "" 66 set text [join [lindex $msg 1] " "] 67 wunderground::main $comd $nick $host $hand $cname $text 68 } 69 70 proc wunderground::main {command nick host hand chan text} { 71 set search [strip $text] 72 set div ""; set moon ""; set sunset ""; set sunrise ""; set windspeed ""; set div "" 73 set winddirection ""; set location ""; set weatherstation ""; set temperature ""; set tempfc "" 74 set conditions ""; set feelslike ""; set feelsf ""; set feelsc ""; set city ""; set day "" 75 set details ""; set forc ""; set count 1; set tempf ""; set state_name ""; set tempc "" 76 set day1 ""; set day2 ""; set day3 ""; set day4 ""; set day5 ""; set state_name "" 77 set day6 ""; set day7 ""; set day8 ""; set day9 ""; set day10 ""; set windgust ""; set feelsfc "" 78 set wundergroundurl "/cgi-bin/findweather/hdfForecast?query=[urlencode $search]" 79 set wundergroundsite "www.wunderground.com" 80 if {"wz" == $command} {set command weather} 81 if {[catch {set wundergroundsock [socket -async $wundergroundsite 80]} sockerr]} { 82 return 0 83 } else { 84 puts $wundergroundsock "GET $wundergroundurl HTTP/1.0" 85 puts $wundergroundsock "Host: $wundergroundsite" 86 puts $wundergroundsock "User-Agent: Opera 9.6" 87 puts $wundergroundsock "" 88 flush $wundergroundsock 89 while {![eof $wundergroundsock]} { 90 set wundergroundvar " [gets $wundergroundsock] " 91 regexp -nocase {"(current)_observation":} $wundergroundvar match div 92 regexp -nocase {"(forecast)":} $wundergroundvar match div 93 regexp -nocase {"(astronomy)":} $wundergroundvar match div 94 if {[regexp -nocase {"city":"([^"]*)} $wundergroundvar match city]} { 95 if {$city == "null"} { 96 set city "" 97 } 98 } elseif {[regexp -nocase {"state_name":"([^"]*)} $wundergroundvar match state_name]} { 99 if {$state_name == "null"} { 100 set state_name "" 101 } 102 set location "${wunderground::tagf}Location: ${wunderground::textf}${city}, $state_name" 103 } elseif {[regexp -nocase {"name":"([^"]*)} $wundergroundvar match weatherstation]} { 104 set weatherstation "${wunderground::tagf}Station: ${wunderground::textf}${weatherstation}" 105 } elseif {$forc == "" && [regexp -nocase {class="wx-unit"> °(.*?)<\/span>} $wundergroundvar match forc]} { 106 } elseif {[regexp -nocase {"condition":"([^"]*)} $wundergroundvar match conditions]} { 107 set conditions "${wunderground::tagf}Conditions: ${wunderground::textf}${conditions}" 108 } elseif {$div == "current" && [regexp -nocase {"temperature":\s([^\,]*)} $wundergroundvar match temperature]} { 109 set tempf "${wunderground::tagf}Temperature: ${wunderground::textf}[forc ${temperature} $forc F] deg F" 110 set tempc "${wunderground::tagf}Temperature: ${wunderground::textf}[forc ${temperature} $forc C] deg C" 111 set tempfc "${wunderground::tagf}Temperature: ${wunderground::textf}[forc ${temperature} $forc F] deg F/[forc ${temperature} $forc C] deg C" 112 } elseif {$div == "current" && [regexp -nocase {"feelslike":\s([^\,]*)} $wundergroundvar match feelslike]} { 113 set feelsf "${wunderground::tagf}Feels Like: ${wunderground::textf}[forc ${feelslike} $forc F] deg F" 114 set feelsc "${wunderground::tagf}Feels Like: ${wunderground::textf}[forc ${feelslike} $forc C] deg C" 115 set feelsfc "${wunderground::tagf}Feels Like: ${wunderground::textf}[forc ${feelslike} $forc F] deg F/[forc ${feelslike} $forc C] deg C" 116 } elseif {$div == "current" && [regexp -nocase {"wind_speed":\s?([^\,]*)} $wundergroundvar match windspeed]} { 117 set windspeed "${wunderground::tagf}Wind speed: ${wunderground::textf}${windspeed}" 118 } elseif {$div == "current" && [regexp -nocase {"wind_gust_speed":\s?([^\,]*)} $wundergroundvar match windgust]} { 119 set windgust "${wunderground::tagf}Wind gust: ${wunderground::textf}${windgust}" 120 } elseif {[regexp -nocase {"wind_dir":"([^"]*)} $wundergroundvar match winddirection]} { 121 set winddirection "${wunderground::tagf}Wind Direction: ${wunderground::textf}${winddirection}" 122 } elseif {[regexp -nocase {id="cc-sun-rise">(.*?)</span>\s?<span class="ampm">(.*?)</span>} $wundergroundvar match sunrise ampm]} { 123 set sunrise "${wunderground::tagf}Sunrise: ${wunderground::textf}${sunrise}${ampm}" 124 } elseif {[regexp -nocase {id="cc-sun-set">(.*?)</span> <span class="ampm">(.*?)</span>} $wundergroundvar match sunset ampm]} { 125 set sunset "${wunderground::tagf}Sunset: ${wunderground::textf}${sunset}${ampm}" 126 } elseif {[regexp -nocase {id="cc-moon-phase".*">(.+?)<\/span>} $wundergroundvar match moon]} { 127 set moon "${wunderground::tagf}Moon: ${wunderground::textf}${moon}" 128 } elseif {$div == "forecast" && $command == "weather"} { 129 msg $chan $wunderground::logo ${wunderground::textf} [subst [regsub -all -nocase {(\S+)} $wunderground::weatherline {$\1}]] 130 close $wundergroundsock 131 return 0 132 } elseif {[regexp -nocase {<div\sclass="fctDayDate">(.+)\,} $wundergroundvar match day]} { 133 set day "${wunderground::tagf}${day}" 134 } elseif {[string match "forecast" $div]} { 135 if {[regexp -nocase {"weekday_short":\s?"([^"]*)} $wundergroundvar match day]} { 136 set day "${wunderground::tagf}${day}:->" 137 } elseif {[regexp -nocase {"high":\s([^\,]*)} $wundergroundvar match high]} { 138 set high "${wunderground::tagf}High:${wunderground::textf}[forc $high $forc F] deg F/[forc $high $forc C] deg C" 139 } elseif {[regexp -nocase {"low":\s([^\,]*)} $wundergroundvar match low]} { 140 set low "${wunderground::tagf}low:${wunderground::textf}[forc $low $forc F] deg F/[forc $low $forc C] deg C" 141 } elseif {[regexp -nocase {"condition":\s?"([^"]*)} $wundergroundvar match condition]} { 142 set condition "${wunderground::tagf}Cond:${wunderground::textf}${condition}" 143 } elseif {[regexp -nocase {"day":\s?\{} $wundergroundvar]} { 144 set day${count} "$day $high $low $condition" 145 incr count 146 } 147 } elseif {$div == "astronomy"} { 148 if {$wunderground::line1 != ""} { 149 msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line1 {$\1}]] 150 } 151 if {$wunderground::line2 != ""} { 152 msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line2 {$\1}]] 153 } 154 if {$wunderground::line3 != ""} { 155 msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line3 {$\1}]] 156 } 157 if {$wunderground::line4 != ""} { 158 msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line4 {$\1}]] 159 } 160 close $wundergroundsock 161 return 0 162 } 163 } 164 } 165 } 166 proc wunderground::forc {value fc forc} { 167 if {[string equal -nocase $fc $forc]} { 168 return $value 169 } elseif {[string equal -nocase "f" $fc]} { 170 if {[expr {(($value - 32) * 5)} == 0]} { return 0 } 171 return [format "%.1f" [expr {(($value - 32) * 5) / 9}]] 172 } elseif {[string equal -nocase "c" $fc]} { 173 if {$value == 0} { return 32 } 174 return [format "%.1f" [expr {(($value * 9) / 5) + 32}]] 175 } 176 } 177 proc wunderground::striphtml {string} { 178 return [string map {" \" < < &rt; >} [regsub -all {(<[^<^>]*>)} $string ""]] 179 } 180 proc wunderground::urlencode {string} { 181 regsub -all {^\{|\}$} $string "" string 182 return [subst [regsub -nocase -all {([^a-z0-9\+])} $string {%[format %x [scan "\\&" %c]]}]] 183 } 184 proc wunderground::strip {text} { 185 regsub -all {\002|\031|\015|\037|\017|\003(\d{1,2})?(,\d{1,2})?} $text "" text 186 return $text 187 } 188 proc wunderground::msg {chan logo textf text} { 189 set text [textsplit $text 50] 190 set counter 0 191 while {$counter <= [llength $text]} { 192 if {[lindex $text $counter] != ""} { 193 $::maintype privmsg $::sock($::cs(netname)) 57 $chan "${logo} ${textf}[string map {\\\" \"} [lindex $text $counter]]" 194 } 195 incr counter 196 } 197 } 198 proc wunderground::textsplit {text limit} { 199 set text [split $text " "] 200 set tokens [llength $text] 201 set start 0 202 set return "" 203 while {[llength [lrange $text $start $tokens]] > $limit} { 204 incr tokens -1 205 if {[llength [lrange $text $start $tokens]] <= $limit} { 206 lappend return [join [lrange $text $start $tokens]] 207 set start [expr $tokens + 1] 208 set tokens [llength $text] 209 } 210 } 211 lappend return [join [lrange $text $start $tokens]] 212 return $return 213 } 214 puts stdout "\002*Loaded* \00304\002W\00304u\00307n\00308d\00311e\00312r\00304g\00307r\00308o\00311u\00312n\00304d\017 \002by \ 215 Ford_Lawnmower irc.GeekShed.net #Script-Help"