This script will retrieve the weather for US zipcodes from the website www.localweather.net.
Update: Added alias so you can trigger it yourself and message the channel with the response.
Update: Added axtra error checking to the alias ( weatherm ). Thanks to Tokensoup.
Update: Added extra stuff for UV and Preassure. ( help from some one who wishes to remain namelss )
Update 1/13/09: Added alteration to specified line as noted by A Hylian Human.
Big Update 1/13/09: Redid entire script. Added forecast option.
Update 1/16/09: Altered triggers and adjusted a few of the script lines.
Triggers listed below:
Updates above no longer valid for the newest version of script.
Will list either weather or forecast.
!w 12345
!w 12345
!weather 12345
!weather 12345
Will list forecast.
!f 12345
!forecast 12345
Update 27Jan10: Completely redid it using another site as the old one changed way to much to use.
Update 4Feb10: Updated Trigger regex thanks to Jethro_ Also updated the script to show Weather Warnings if there are any.
on $*:text:/^!w(eather)?|f(orecast)?/Si:#: {
if ($2 isnum) {
if ($istok(!w !weather,$1,32)) { set %usweatherWF W }
if ($istok(!f !forecast,$1,32)) { set %usweatherWF F }
set %usweatherzip $2 | set %usweatherchan $chan
sockopen usweather www.localweather.net 80
}
}
on *:sockopen:usweather: {
sockwrite -n $sockname GET $+(/weather/?pands=,%usweatherzip,&forecast=zandh) HTTP/1.1
sockwrite -n $sockname Host: www.localweather.net
sockwrite -n $sockname Connection: close
sockwrite -n $sockname Authorization: Basic
sockwrite -n $sockname $crlf
}
on *:sockread:usweather: {
sockread %whtemp
if (warnings.html isin %whtemp) { set %whtempwarn $remove($nohtml(%whtemp),$chr(9),Advisories) }
if (Location Not Found isin %whtemp) { set %whtempwrong Yes }
if (class="pname"> isin %whtemp) { set %whtemplocation $remove($nohtml(%whtemp),$chr(9)) }
; Weather
if (Lat: isin %whtemp) { set %whtemplat $remove($nohtml(%whtemp),$chr(9)) }
if (class="u-met"> isin %whtemp) { inc %t_t 1 | set %whtemperC $+ %t_t $remove($nohtml(%whtemp),$chr(9)) }
; Forecast
if (class="dt"> isin %whtemp) { inc %yy 1 | set %suweatherdate $+ %yy $remove($nohtml(%whtemp),$chr(9)) }
if (class="hi"> isin %whtemp) { inc %ii 1 | set %suweatherhi $+ %ii $remove($nohtml(%whtemp),$chr(9)) }
if (class="lo"> isin %whtemp) { inc %iii 1 | set %suweatherlo $+ %iii $remove($nohtml(%whtemp),$chr(9)) }
if (class="wx"> isin %whtemp) { inc %oo 1 | set %suweathercondition $+ %oo $remove($nohtml(%whtemp),$chr(9)) }
}
on *:sockclose:usweather: {
if (%whtempwrong = Yes) {
msg %usweatherchan That zip code is incorrect. Please try another one.
unset %t_t %y_y %whtemp* %usweather* %suweather* %oo %yy %ii
}
else {
msg %usweatherchan Location:12 %whtemplocation
if (%usweatherWF = W) {
var %whcurF $gettok(%whtemperC1,1,38) $+ $chr(176) F
var %whcurC $round($calc(($gettok(%whtemperC1,1,38) - 32) * 5/9),0) $+ $chr(176) C
msg %usweatherchan Latitude:03 $removecs($gettok(%whtemplat,4,58),N,E,S,W,Lon) Longitude:03 $removecs($gettok(%whtemplat,5,58),N,E,S,W,Lon)
msg %usweatherchan Currently:07 %whcurF /07 %whcurC and $gettok(%whtemperC1,2-,67) $&
Feels Like:7 $replace($gettok($remove(%whtemperC2,Feels Like:),1,70),°,$+($chr(176),$chr(32),F)) $&
/07 $round($calc($gettok($remove(%whtemperC2,Feels Like:),1,38) -32) *5/9),1) $+ $+($chr(176),$chr(32),C)
msg %usweatherchan Dew Point:13 $replace($gettok($gettok(%whtemperC3,2,58),1,70),°,$chr(176)) $+ $+($chr(32),F)) $&
/13 $round($calc($gettok($remove(%whtemperC3,Dew Point:),1,38) -32) *5/9),1) $+ $+($chr(176),$chr(32),C) $&
Pressure:10 $+($gettok($remove(%whtemperC5,Pressure:),1,110),n) /10 $gettok(%whtemperC5,2,110)
if (%whtempwarn) { msg %usweatherchan Weather Warning: $+ $+($chr(3),4,%whtempwarn) }
msg %usweatherchan Website: http://www.localweather.net/weather/?pands= $+ %usweatherzip $+ &forecast=zandh
}
if (%usweatherWF = F) {
msg %usweatherchan 7 $+ $usweather(%suweatherdate2) 4>>12 $iif(%suweatherhi1 = %suweatherlo2,$usweather2(%suweatherlo1),$usweather2($v1)) 4>>>3 %suweathercondition2
msg %usweatherchan 7 $+ $usweather(%suweatherdate3) 4>>12 $usweather2(%suweatherhi1) 4>>>3 %suweathercondition3
msg %usweatherchan 7 $+ $usweather(%suweatherdate4) 4>>12 $usweather2(%suweatherhi2) 4>>>3 %suweathercondition4
msg %usweatherchan 7 $+ $usweather(%suweatherdate5) 4>>12 $usweather2(%suweatherhi3) 4>>>3 %suweathercondition5
msg %usweatherchan 7 $+ $usweather(%suweatherdate6) 4>>12 $usweather2(%suweatherhi4) 4>>>3 %suweathercondition6
msg %usweatherchan 7 $+ $usweather(%suweatherdate7) 4>>12 $usweather2(%suweatherhi5) 4>>>3 %suweathercondition7
msg %usweatherchan 7 $+ $usweather(%suweatherdate8) 4>>12 $usweather2(%suweatherhi6) 4>>>3 %suweathercondition8
$iif($gettok(%suweatherdate9,2,32) isnum,msg %usweatherchan 7 $+ $usweather(%suweatherdate9) 4>>12 $usweather2(%suweatherhi7) 4>>>3 %suweathercondition9 )
$iif($gettok(%suweatherdate10,2,32) isnum,msg %usweatherchan 7 $+ $usweather(%suweatherdate10) 4>>12 $usweather2(%suweatherhi8) 4>>>3 %suweathercondition10 )
}
unset %t_t %y_y %whtemp* %usweather* %suweather* %oo %yy %ii %iii
}
}
alias usweather {
return $iif($istokcs(MON TUE WED THU FRI SAT SUN,$left($1,3),32),$replace($1,$left($1,3),$+($left($1,3),$chr(32))),$+($1,$chr(32)))
}
alias usweather2 {
return $replacecs($replace($1,:,$+(:,$chr(32)),°,$+($chr(176),$chr(32))),F,$+(F,$chr(32)))
}
alias -l nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
1)
on $:text:/^!w(eather)?|f(orecast)?/Si:#: {
if ($2 isnum) {
if ($istok(!w !weather,$1,32)) { set %usweatherWF W }
if ($istok(!f !forecast,$1,32)) { set %usweatherWF F }
set %usweatherzip $2 | set %usweatherchan $chan
sockopen usweather www.localweather.net 80
}
ignore -u60 !@
}
no flood:)
2) www.localweather.com, not www.localweather.net
3) msg %usweatherchan Latitude:03 $removecs($gettok(%whtemplat,3,58),N,E,S,W,Lon) Longitude:03 $removecs($gettok(%whtemplat,4,58),N,E,S,W,Lon)
hey would it be possible to make it save locations based on usesrs. and could you make it look nice and tidy like this one :)
[12:17:32am] !w
[12:17:35am] <+Amy> Baytown, Texas (29.8°N 95.0°W) - Updated: 00:56 CDT
[12:17:36am] <+Amy> Conditions: Partly Cloudy - Temperature: 17.2°C (63°F) - High/Low: 24/18°C (75/64°F)
[12:17:36am] <+Amy> Dew Point: 17°C (63°F) - Humidity: 95%
[12:17:37am] <+Amy> Wind: SSE at 4.0 MPH (6.4 KPH)
All I know now that the weather code that Erunner did works. But I would like it where I can also type the weather trigger and it lets me in on seeing the weather also. It would be neat if it did something for us too. Well I know it works b/c I had a friend come inside and did the weather thing for hisself and it works.
The following regex
/^!w(eather)?|f(orecast)?/Si
is incorrect. It will trigger when someone simply says "f" instead of "!f".
This is made worse by the fact that the regex isn't locked to even a word break, so any word starting with "f" will set it off...
To fix it easily you can use
/^!(w(eather)?|f(orecast)?)\b/Si
That's why it needs the parentheses around the main regex.
Ive discovered an issue - not sure if its just my remotes conflicting or if its this scripting - could you test this and verify?
random text is setting the script off and returning > That zip code is incorrect. Please try another one.
Example - type in a random word followed by random numbers. foxtrot 38919230 No trigger or nothing.
Previously it was .... ; Usage /weatherm 12345 or /weatherm 12345 forecast
That permitted me to do something like this
on *:text:!bhweather:#: {
/weatherm 90210
}
So users never knew how to call zipcodes they only knew how to call the trigger.
How would I structure the trigger coding for what you have given?
Would it be
on *:text:!bhweather:#: {
$weatherm(90210,W)
}
Ohhhhh and sorry to bother ya - how hard would it be to add in "humidity" and "wind" to the script ? I think the old script had those ...
Thanks again!
So is this working for you?
Also the previous version had some command lines >
; Usage /weatherm 12345 or /weatherm 12345 forecast
Would be great if this one used command lines as well so that I could set up the bot to use an alternate trigger - I dont want 500 people all trying to put in their zip codes ... if they only know 1 trigger
!givemeweather , and that called up the actual trigger it be awesome.
I overlooked a matter that the parentheses in the regex match will confuse mirc for $regml(1) when entering the optional command !weather or !forecast
I edited my suggestion to reflect the change below:
on $*:text:/^!w(eather)?\s\d+|f(orecast)?\s\d+/Si:#: {
if ($istok(!w !weather,$1,32)) { set %usweatherWF W }
if ($istok(!f !forecast,$1,32)) { set %usweatherWF F }
set %usweatherzip $2 | set %usweatherchan $chan
sockopen usweather www.localweather.net 80
}
You're welcome, Scakk.
This:> on $*:text:/^!w(eather)?|f(orecast)?/Si:#: {
if ($2 isnum) {
if ($istok(!w !weather,$1,32)) { set %usweatherWF W }
if ($istok(!f !forecast,$1,32)) { set %usweatherWF F }
set %usweatherzip $2 | set %usweatherchan $chan
sockopen usweather www.localweather.net 80
}
}
Can be:
on $*:text:/^!w(eather)?\s(\d+)|f(orecast)?\s(\d+)/Si:#: {
if ($istok(!w !weather,$1,32)) { set %usweatherWF W }
if ($istok(!f !forecast,$1,32)) { set %usweatherWF F }
set %usweatherzip $regml(1) | set %usweatherchan $chan
sockopen usweather www.localweather.net 80
}
which saves the if $2 isnum statement and an end bracket.
This regex can be changed:> on $*:text:/^!/Si:#: {To:
on $*:text:/^!w(eather)?|f(orecast)?/Si:#: {
which saves an additional use of the letter w and f. And the [] isn't necessary since you want to match for the exclamation mark only. Also, no $regml(1) is referenced so the outer () can be omitted.
00:30] <CrazyFrog
On
Lilypad> .:( Location: ):.[00:30] <CrazyFrog
On
Lilypad> .:( Latitude: Longitude: ):.[00:30] <CrazyFrog
On
Lilypad> .:( Currently: ° F / -18° C and ):.[00:30] <CrazyFrog
On
Lilypad> .:( Dew Point: F ):.[00:30] <CrazyFrog
On
Lilypad> .:( Website: http://www.localweather.net/weather/?pands=31639&forecast=zandh ):.this weather FILE ISNT WORKING AS YOU CAN SEE ABOVE