I'm not good with Regular Expressions, and Perl conventions even less
so. If someone can piece this together, I'd be grateful:
Code:
--------------------
my $outcome_txt = ($tree->look_down( "_tag", "div", "class",
"wx-details"))[0];
if ($outcome_txt) {
if ($outcome_txt->as_text =~ m/Chance of \w+:(.*%)W/) {
$wetData{-1}{'forecastPrec'} = $1;
$wetData{0}{'forecastPrec'} = $1;
}
else {
$status = '-';
$log->warn('Error parsing current/today precip');
}
}
--------------------
The HTML it's looking for is:
Code:
--------------------
<div class="wx-data-part wx-first">
<h6 class="wx-label">Past 24-hr Precip:</h6>
<div class="wx-data">0 in</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label">Chance of <span class='wx-firstletter'>rain</span></h6>
<div class="wx-data"><span class="wx-icon wx-raindrop"></span>60%</div>
</div>
<div class="wx-data-part">
<h6 class="wx-label">Chance of <span class='wx-firstletter'>rain</span></h6>
<div class="wx-data"><span class="wx-icon wx-raindrop"></span>60%</div>
</div>
--------------------
If I interpret this correctly, there is a single value that it's
populating into 2 variables (even though the variable is available as 2
distinct values -- weird. Easier?) I think forecastPrec is looking for
the % value "60%", and not the description "rain". The code looks like
it's looking for:
"Chance of <something>: ##%<more something>" and puts the ## characters
into $1. if so, I'd change the code to be:
Hmm.. this is going to be tough - there are MANY <div> with the class of
"wx-data-part wx-first" as well as "wx-data". It looks like look_down
is grabbing the first item in the array of results, so if we know WHICH
item it should be, then this is easy(-ier). Hopefully that result array
is consistent... hmmmm...
It looks like the forecastPrec is result 3 ([2] in the array). If we
capture that, the regular expression could be:
(from this site I'm using for testing:
http://www.solmetra.com/scripts/regex/index.php)
Code:
--------------------
/<span(.*?)><\/span>(.*?)\%<\/div>/
--------------------
That returns an array of results, where [2] is the value we want.
Whew...
------------------------------------------------------------------------
plympton's Profile: http://forums.slimdevices.com/member.php?userid=12955
View this thread: http://forums.slimdevices.com/showthread.php?t=14327
_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins