mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2022
Posts: 3
G
glen Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
G
Joined: Dec 2022
Posts: 3
i am sure i am doing something stupid, i have a script, it reads the socket and sets the var correctly, but it refuses to set the words i want set.

so the socket line says BLAH1 BLAH2 BLAH3 BLAH4 and i want it to set %XYZ to be BLAH3 but it won't it just sets %XYZ to be blank.


on 1:sockread:metar:{
sockread %temp
if (KMCI isin %temp) { set %mci %temp | set %kmci true | msg wx line: $1- | set %line $1- }
echo 4 %temp
}


in my scripot it sets %mci to be the %temp line and %kmci to true but it will not message me the line nor will it set %line to be anything other than empty.
what am i doing wrong?

Joined: Jan 2004
Posts: 2,002
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,002
$1- is blank because there is no $1- in the ON SOCKREAD event. What do you think should be the contents of $1-? if it's the contents of %temp, then use %temp not $1-
If you have several network status windows, the ON SOCKREAD executes at whichever connection you did the /sockopen command.
The /msg will be sent to the nick 'wx', but since you're using the empty $1- that's what you'll get, nothing.

Joined: Dec 2022
Posts: 3
G
glen Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
G
Joined: Dec 2022
Posts: 3
so set %mci %temp gets me %mci <td align="right" valign="top"><span style="color: #9999CC; font-weight: bold">Text:</span></td><td style="background-color: #CCCCCC; font-weight: bold">KMCI 150453Z 27009KT 10SM OVC035 02/M04 A2965 RMK AO2 SLP044 T0022

but what i really want is %mci to be the text starting with KMCI and going to the end of the line,
later in the script i will extracting only a word or two from similar lines.

so how do i tell it that %mci or %xxx be just a word or two or three from %temp

Joined: Jan 2004
Posts: 2,002
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,002
if you want the text beginning with a specific string, this will do that:

//var %temp <td align="right" valign="top"><span style="color: #9999CC; font-weight: bold">Text:</span></td><td style="background-color: #CCCCCC; font-weight: bold">KMCI 150453Z 27009KT 10SM OVC035 02/M04 A2965 RMK AO2 SLP044 T0022 | var -s %pos $pos(%temp,KMCI,1) | var -s %kmci $mid(%temp,%pos)

If you want to extract words from this substring, it depends on whether you want the Nth word, the word matching a wildcard, etc - see the /help page for the token functions like $gettok $findtok $wildtok etc. It's hard to know what to tell you without knowing what the input is likely to be like

Joined: Dec 2022
Posts: 3
G
glen Offline OP
Self-satisfied door
OP Offline
Self-satisfied door
G
Joined: Dec 2022
Posts: 3
here is an example of what i need to extract..

<td align="right"><span style="color: #9999CC; font-weight: bold">Temperature:</span></td><td> 2.2°C ( 36°F)</td>
</tr>
<tr>
<td align="right"><span style="color: #9999CC; font-weight: bold">Dewpoint:</span></td><td> -3.9°C ( 25°F) [RH = 64%]</td>
</tr>
<tr>
<td align="right"><span style="color: #9999CC; font-weight: bold">Pressure (altimeter):</span></td><td>29.65 inches Hg (1004.1 mb) [Sea level pressure: 1004.4 mb]</td>
</tr>
<tr>
<td align="right"><span style="color: #9999CC; font-weight: bold">Winds:</span></td><td>from the W (270 degrees) at 10 MPH (9 knots; 4.6 m/s)</td>
</tr>
<tr>


so each of those lines i need to extract the (36°f) and the (25&degF) etc etc and only those phrases in those lines.

Joined: Jan 2004
Posts: 2,002
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,002
A quick and dirty regex that matches your examples. It finds the string bold"> and then captures all characters until it encounters a < char. Then finds another string of not-containing-< as described in your example. If your match ends up being split across lines or has several of these 'lines' all in the same sockread string, then it would need to be modified.

var %pattern bold">([^<]+)<\/span><\/td><td>([^<]+)<\/td>

if ($regex(%temp,%pattern)) {
echo -a match1: $regml(1)
echo -a match2: $regml(2)
}


Link Copied to Clipboard