It is currently April 24th, 2024, 6:58 am

Code Concept Question

General topics related to Rainmeter.
User avatar
UnstoppableDave
Posts: 30
Joined: May 22nd, 2010, 6:51 pm

Re: Code Concept Question

Post by UnstoppableDave »

Ah! I was hoping there was something like that. Yeah, I was trying to understand it but most of the lingo was way over my head.
Thanks for explaining it.
About the multiple entries, do you mean that if I say something like,

(?(?=.*<item>)<item>(.*)</item>.*<price>(.*)</price>)

and later in the code there are more items with prices, following exactly the same repitition, then it will return those as well? RainRegExp was acting this way with regular parsers so I wasn't sure.
Image
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Code Concept Question

Post by jsmorley »

Here is a working example that might make it more clear:

Create a folder under My Documents\Rainmeter\Skins. Then in that folder:

Save this text as LookAhead.html

Code: Select all

<html>
<body>
<pubdate>18 January, 2010</pubdate>
<item>
<subject>This is item 1</subject>
<author>Larry</author>
<text>This is the text of item 1</text>
</item>
<item>
<subject>This is item 2</subject>
<author>Moe</author>
<text>This is the text of item 2</text>
</item>
<item>
<subject>This is item 3</subject>
<author>Curly Joe</author>
<text>This is the text of item 3</text>
</item>
</body>
</html>
Save this text as LookAhead.ini

Code: Select all

[Rainmeter]
DynamicWindowSize=1
Update=1000

[Variables]
GET=(?(?=.*<item>).*<subject>(.*)</subject>.*<author>(.*)</author>)

[TextStyle]
X=0
Y=2R
FontSize=13
FontColor=255,255,255,255
AntiAlias=1

[MeasureTestSite]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=file://#CURRENTPATH#LookAhead.html
RegExp="(?siU)<pubdate>(.*)</pubdate>#GET##GET##GET##GET##GET##GET##GET##GET##GET##GET#"
UpdateRate=60

[MeasurePubDate]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=1

[MeasureSubject1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=2

[MeasureAuthor1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=3

[MeasureSubject2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=4

[MeasureAuthor2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=5

[MeasureSubject3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=6

[MeasureAuthor3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[MeasureTestSite]
StringIndex=7

[MeterPubDate]
Meter=String
MeasureName=MeasurePubDate
MeterStyle=TextStyle

[MeterSubject1]
Meter=String
MeasureName=MeasureSubject1
MeterStyle=TextStyle

[MeterAuthor1]
Meter=String
MeasureName=MeasureAuthor1
MeterStyle=TextStyle

[MeterSubject2]
Meter=String
MeasureName=MeasureSubject2
MeterStyle=TextStyle

[MeterAuthor2]
Meter=String
MeasureName=MeasureAuthor2
MeterStyle=TextStyle

[MeterSubject3]
Meter=String
MeasureName=MeasureSubject3
MeterStyle=TextStyle

[MeterAuthor3]
Meter=String
MeasureName=MeasureAuthor3
MeterStyle=TextStyle
Refresh Rainmeter and load the skin. I have it looking for 10 iterations (using #GET# to keep the RegExp line from being so long) of "Subject" and "Author", but there are only 3 in the file (pretend it's a web site) and it works just fine.

As poiru said, the long and the short of it (without getting into the mind-numbing explanation on the Regular Expression site) is that:

This: (?(?=

is saying do this: .*<subject>(.*)</subject>.*<author>(.*)</author>

if this is found: .*<item>

But don't "fail" if not...
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Code Concept Question

Post by jsmorley »

UnstoppableDave wrote:Ah! I was hoping there was something like that. Yeah, I was trying to understand it but most of the lingo was way over my head.
Thanks for explaining it.
About the multiple entries, do you mean that if I say something like,

(?(?=.*<item>)<item>(.*)</item>.*<price>(.*)</price>)

and later in the code there are more items with prices, following exactly the same repitition, then it will return those as well? RainRegExp was acting this way with regular parsers so I wasn't sure.
No, WebParser is slightly different than the standard PCRE Regular Expression used in RainRegExp as it only returns the "first" successful capture of a pattern. This is to keep a big site from causing WebParser to just "run away" and cause problems. If you want to capture more than one instance, you need to repeat the pattern in the RegExp.
User avatar
UnstoppableDave
Posts: 30
Joined: May 22nd, 2010, 6:51 pm

Re: Code Concept Question

Post by UnstoppableDave »

Ah ok. Thanks for the example skin, that really helped. Man, this thing is picky... but I think I finally got mine working. This is going to be sweet 8-)
And thanks for all your help guys. :D Assuming I don't hit anymore snags, you'll probably see it in the skin development section in the next day or so.
Image