It is currently March 29th, 2024, 4:46 am

Lookahead issue

Get help with creating, editing & fixing problems with skins
Bundi
Posts: 20
Joined: October 11th, 2016, 6:46 am

Lookahead issue

Post by Bundi »

Hi,

I am trying to do a skin for a webpage with pollen report.

The page reports the levels in 6 different levels, L, L-M, M, M-H, H, & H+
and there are two more for when there is no levels recorded i.h and also one for when there is no measurement i.u.

I would like to just parse out the different 6 levels, and of course the i.u and i.h

I then have the intention to use substitute these to numeric values and make bar-graph's to display the different values. But once I have these parsed, I should manage that part.

The trick for me is when there is the i.u and i.h, as the "tag" I use for parsing changes, this is what the source looks like for today:

Code: Select all

<div id="pollenreport_day_20170323" style="display:inline;">
				<table width="100%" cellpadding="0" cellspacing="0">
					<tbody>
		
				<tr class="pollenruta">
					<td>
						<strong>Al:</strong>
					</td>
					<td>
						<div class="rapport_h"></div>H
					</td>
				</tr>
				<tr class="pollenruta1">
					<td>
						<strong>Alm:</strong>
					</td>
					<td>
						<div class="rapport_l"></div>L
					</td>
				</tr>
				<tr class="pollenruta">
					<td>
						<strong>Björk:</strong>
					</td>
					<td>
						i.h.
					</td>
				</tr>
				<tr class="pollenruta1">
					<td>
						<strong>Bok:</strong>
					</td>
					<td>
						i.h.
					</td>
				</tr>
				<tr class="pollenruta">
					<td>
						<strong>Ek:</strong>
					</td>
					<td>
						i.h.
					</td>
				</tr>
				<tr class="pollenruta1">
					<td>
						<strong>Gräs:</strong>
					</td>
					<td>
						i.h.
					</td>
				</tr>
				<tr class="pollenruta">
					<td>
						<strong>Gråbo:</strong>
					</td>
					<td>
						i.h.
					</td>
				</tr>
				<tr class="pollenruta1">
					<td>
						<strong>Hassel:</strong>
					</td>
					<td>
						<div class="rapport_l_m"></div>L-M
					</td>
				</tr>
				<tr class="pollenruta">
					<td>
						<strong>Sälg / vide:</strong>
					</td>
					<td>
						<div class="rapport_l"></div>L
					</td>
				</tr>
					</tbody>
				</table>
				
			</div>
I have tried with a few different lookahead attempts, but I am not managing to extract what I need.

The URL I am trying to parse from is this one:
http://pollenkoll.se/pollenprognos-malmoe

Thankful for suggestions on how to do this RegEx with lookahead.

Best,
Bundi
Last edited by Bundi on March 24th, 2017, 1:32 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lookahead issue

Post by balala »

In my opinion, in this case the lookahead is useful only if the number of the measurements is variable.
However, try the following code:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
Item=(?(?=.*<str)ong>(.*)</strong>.*</td>.*<td>(.*)</td>)

[MeasureRainmeter]
Measure=Plugin
Plugin=WebParser
Url=http://pollenkoll.se/pollenprognos-malmoe
RegExp=(?siU)<strong>(.*)</strong>.*</td>.*<td>(.*)</td>.*#Item#.*#Item#.*#Item#.*#Item#.*#Item#.*#Item#.*#Item#.*#Item#.*#Item#

[MeasureLocation1]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=1

[MeasureValue1]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=2
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation2]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=3

[MeasureValue2]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=4
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation3]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=5

[MeasureValue3]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=6
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation4]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=7

[MeasureValue4]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=8
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation5]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=9

[MeasureValue5]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=10
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation6]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=11

[MeasureValue6]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=12
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation7]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=13

[MeasureValue7]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=14
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation8]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=15

[MeasureValue8]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=16
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation9]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=17

[MeasureValue9]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=18
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeasureLocation10]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=19

[MeasureValue10]
Measure=Plugin
Plugin=WebParser
Url=[MeasureRainmeter]
StringIndex=20
RegExpSubstitute=1
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':""

[MeterValues]
MeasureName=MeasureLocation1
MeasureName2=MeasureValue1
MeasureName3=MeasureLocation2
MeasureName4=MeasureValue2
MeasureName5=MeasureLocation3
MeasureName6=MeasureValue3
MeasureName7=MeasureLocation4
MeasureName8=MeasureValue4
MeasureName9=MeasureLocation5
MeasureName10=MeasureValue5
MeasureName11=MeasureLocation6
MeasureName12=MeasureValue6
MeasureName13=MeasureLocation7
MeasureName14=MeasureValue7
MeasureName15=MeasureLocation8
MeasureName16=MeasureValue8
MeasureName17=MeasureLocation9
MeasureName18=MeasureValue9
MeasureName19=MeasureLocation10
MeasureName20=MeasureValue10
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=1. %1 %2#CRLF#2. %3 %4#CRLF#3. %5 %6#CRLF#4. %7 %8#CRLF#5. %9 %10#CRLF#6. %11 %12#CRLF#7. %13 %14#CRLF#8. %15 %16#CRLF#9. %17 %18#CRLF#10. %19 %20
This code will check up to ten measurements. It'll show the location and the measured value, or i.h, if that's provided. Obviously you can add further #Item# variables to the RegExp option of the [MeasureRainmeter] and the appropriate [MeasureLocationXX] respectively [MeasureValueXX] measures. If you do so, don't forget to complete the string meter with the needed options to can show everything.
Is this looking as you'd like it?
Bundi
Posts: 20
Joined: October 11th, 2016, 6:46 am

Re: Lookahead issue

Post by Bundi »

Thanks a lot "balala",

Working excellent, just as intended.
Now attempting to add a substitute as well for the levels into digits as I mentioned.
Think I will succeed with that.

Then I will add the bar-graph's as well.

Thanks a lot for all the time you spent on this and helping me out!

All the best "balala"!

/Bundi
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lookahead issue

Post by balala »

Bundi wrote:Thanks a lot "balala",

Working excellent, just as intended.
Now attempting to add a substitute as well for the levels into digits as I mentioned.
Think I will succeed with that.

Then I will add the bar-graph's as well.

Thanks a lot for all the time you spent on this and helping me out!

All the best "balala"!

/Bundi
Glad to help.
To make the needed substitutions, I recommend to add further elements to the Substitute options of the [MeasureValue1] - [MeasureValue10] measures, replacing those options, with the following one:

Code: Select all

[MeasureValue1]
...
Substitute="\n":"","\s+":"","</div>":"",'<divclass=".*">':"","^L$":"1","^L-M$":"2","^M$":"3","^M-H$":"4","^H$":"5","^H+$":"6","^i.h.$":"0","^i.u.$":"0"
If you do so, there will be a problem: a bar meter won't use the substituted values, returned by those WebParser plugin measures. You'll have to create some Calc measures, where you'll have to set the dynamic variables. Eg, to create a bar meter which will show the value returned by the [MeasureValue1] measure, you'll need the following measure:

Code: Select all

[MeasureCalc1]
Measure=Calc
Formula=[MeasureValue1]
DynamicVariables=1
MinValue=0
MaxValue=6
Two very important things here are the Formula (the substituted value of the WebParser plugin measure, is a string, the brackets will convert this value into a numeric value) and in such cases the needed DynamicVariables=1 option).
Having this measure, now you can create a Bar meter:

Code: Select all

[MeterLine1]
Meter=Bar
MeasureName=MeasureCalc1
X=0r
Y=10R
W=100
H=10
BarColor=255,0,0
SolidColor=255,255,255
BarOrientation=Horizontal
Obviously you can create further Calc measures and Bar meters for each of the [MeasureValueXX] measures.
Bundi
Posts: 20
Joined: October 11th, 2016, 6:46 am

Re: Lookahead issue

Post by Bundi »

Wow!

Great "balala"!

Looks excellent, I am working on the skin itself now. And it works just as I wanted it to.
I was thinking in the ways to add extra measures and then use substitute on that measure for input to the bar-graphs.
But I didn´t get that far yet, and I hadn´t of course forseen all the things you told me about with calculation issues and so on.

Thanks again "balala" for solving all the issue and answering my questions!

All the best!

Have a great weekend!
many thanks,
Bundi
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lookahead issue

Post by balala »

Glad to help.
If you have further questions regarding those extra measures (or anything else), please let us know.
Also wishing a great weekend (at least what remained from it).