New weather script I made using dialog. Retrieves more info than the last one...
menu * {
-
Weather: wea
}
alias htmlfree {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
alias wea dialog -m wea wea
dialog wea {
title "Weather Script"
size -1 -1 334 356
option pixels
button "Close", 1, 259 321 65 25
edit "", 2, 25 16 288 20
button "Search ZIP/Full Location", 3, 87 48 132 25
box "Weather Forcast and Results", 4, 17 77 308 234
text "", 5, 25 100 279 17
text "", 15, 76 275 250 17, center
text "", 6, 25 124 279 17
text "", 7, 25 153 279 17
text "", 8, 26 182 279 17
text "", 9, 26 211 279 17
text "", 10, 28 238 279 17
text "", 13, 28 238 279 17
text "", 11, 28 323 213 17
}
on *:sockopen:wea: {
sockwrite -nt $sockname GET /cgi-bin/findweather/getForecast?query= $+ $replace(%wea.search,$chr(32),+) $+ &wuSelect=WEATHER HTTP/1.1
sockwrite -nt $sockname Host: www.wunderground.com
sockwrite -nt $sockname $crlf
}
on *:sockread:wea: {
if (!$sockerr) {
var %wea
sockread %wea
if (*<h1>*</h1>* iswm %wea) {
hadd -m $sockname Title $htmlfree(%wea)
}
if (*<span class="nobr"><span class="b">*</span> °F</span>* iswm %wea) { hadd $sockname Temp $replace($htmlfree(%wea),#176;,$+($chr(186),$chr(32))) }
if (*style="font-size: 14px;">*</div>* iswm %wea) { hadd -m $sockname Condition $htmlfree(%wea) }
if (*<nobr>*%</nobr><* iswm %wea) { tokenize 32 %wea | hadd -m $sockname Humidity $htmlfree(%wea) }
if (*<span class="nobr"><span class="b">*</span> °F</span>* iswm %wea) { hadd -m $sockname Dewpoint $replace($htmlfree(%wea),°,$chr(186) $+ $chr(32)) }
if (*<span class="nobr"><span class="b">*</span> mph</span>* iswm %wea) { hadd -m $sockname Windspeed $replace($htmlfree(%wea), ,$chr(32)) }
if (*<b>*</b> in* iswm %wea) { hadd -m $sockname Pressure $replace($htmlfree(%wea), ,$chr(32)) }
if (*<b>*</b>* iswm %wea) {
hadd $sockname Clouds $htmlfree(%wea)
sockclose wea
did -a wea 15 $iif(%wea.err != on,$hget(wea,Title),Error: Invalid/Nonspecific Search. Try again.)
did -a wea 5 $iif(%wea.err != on,Tempurature: $hget(wea,Temp),$chr(32))
did -a wea 6 $iif(%wea.err != on,Condition: $right($hget(wea,Condition),-2),$chr(32))
did -a wea 7 $iif(%wea.err != on,Humidity: $right($hget(wea,Humidity),-2),$chr(32))
did -a wea 8 $iif(%wea.err != on,Dew Point: $hget(wea,Dewpoint),$chr(32))
did -a wea 9 $iif(%wea.err != on,Wind Speed: $hget(wea,Windspeed),$chr(32))
did -a wea 10 $iif(%wea.err != on,Pressure: $hget(wea,Pressure),$chr(32))
did -a wea 13 $iif(%wea.err != on,Clouds: $hget(wea,Clouds),$chr(32))
did -a wea 11 $+($chr(77),$chr(97),$chr(100),$chr(101),$chr(32),$chr(98),$chr(121),$chr(32),$chr(84),$chr(104),$chr(101),$chr(78),$chr(105),$chr(116),$chr(101),$chr(108),$chr(121),$chr(102),$chr(101))
unset %wea.*
}
if (Scroll down to view a list of all all cities isin %wea) { set %wea.err on | halt }
if (Click on a column heading to sort this information isin %wea) { set %wea.err on | halt }
if (There has been an error isin %wea) { set %wea.err on | halt }
}
}
on *:dialog:wea:*:*: {
if ($devent == sclick) {
if ($did == 1) { dialog -x $dname $dname }
else {
if (!$sock(wea)) {
$iif($did(2),set %wea.search $did(2),halt)
sockopen wea www.wunderground.com 80
}
}
}
}
About the tokenize part: I edited this crap like 20 times, and I realized I didn't need to tokenize :\ Forgot that part though.
Also I don't really like sockmark and aren't you the one always saying use hash tables? :p
%wea.err is set when you give a bad search and it doesn't return anything.
Updated
if (%<* iswm %wea) { tokenize 32 %wea | hadd -m $sockname Humidity $htmlfree(%wea) }
why did u put tokenize?
and where is %wea.err
if ($did == 1) { dialog -x $dname $dname } <= -x parameter is only for name so u can put only one $dname like this
if ($did == 1) dialog -x $dname
good job but u can also use sockmark instead hash tables