It is currently April 27th, 2024, 8:58 pm

Little Help with RegExp / Search String showing in output

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

balala wrote: November 20th, 2018, 1:37 pm The above [MeasureReviews] measure returns reviews_available":19,, even if I add a StringIndex=1 option to [MeasureReviews]. With or without StringIndex, I get the same result.
I resist that...
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

Code: Select all

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

[Variables]

[MeasureReviews]
Measure=WebParser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)reviews_available":(.*),
StringIndex=1

[MeterResult]
Meter=String
MeasureName=MeasureReviews
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Test.html:

Code: Select all

{"reviews_available":19,"next_review_date":1541692800,"reviews_available_next_hour":19,"reviews_available_next_day":19}}
1.png
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

balala wrote: November 20th, 2018, 1:37 pm The above [MeasureReviews] measure returns reviews_available":19,, even if I add a StringIndex=1 option to [MeasureReviews]. With or without StringIndex, I get the same result.
You are confusing / conflating [MeasureSite] with [MeasureReviews].

For his simple purposes, you can have a "parent' of [MeasureSite] and a "child" of [MeasureReviews], or you can have a single measure that is BOTH a "parent" and a "child", call it either name, MeasureSite or MeasureReviews, that isn't important.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Little Help with RegExp / Search String showing in output

Post by balala »

jsmorley wrote: November 20th, 2018, 1:54 pm You are confusing / conflating [MeasureSite] with [MeasureReviews].
No, I don't. What I meant was that if I use the code posted by you here:
jsmorley wrote: November 20th, 2018, 1:02 pm

Code: Select all

[MeasureSite]
Measure=Webparser
URL=https://bunpro.jp/api/user/#APIKey#/study_queue
RegExp=(?siU)^(.*)$

[MeasureReviews]
Measure=Webparser
URL=[MeasureSite]
RegExp=(?siU)reviews_available":(.*),
I get reviews_available":19,, even if I add the StringIndex=1 option to [MeasureReviews] (obviously I replaced the URL option of [MeasureSite]).
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

The long and the short of it is that WebParser can take a minute to wrap your head around, but once you do, it follows pretty simple rules:

1) Any WebParser measure with a RegExp on it is a "parent". It does two things, it returns the entire "match" created by the regular expression as the string value of the measure, and creates an index table of any (capture groups) that are defined in the regular expression.

2) Any WebParser measure with a StringIndex on it is a "child". It does one thing. It extracts the value of the indexed (capture group) from the parent, and sets that as the string value of the measure.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Little Help with RegExp / Search String showing in output

Post by balala »

jsmorley wrote: November 20th, 2018, 2:13 pm The long and the short of it is that WebParser can take a minute to wrap your head around, but once you do, it follows pretty simple rules:

1) Any WebParser measure with a RegExp on it is a "parent". It does two things, it returns the entire "match" created by the regular expression as the string value of the measure, and creates an index table of any (capture groups) that are defined in the regular expression.

2) Any WebParser measure with a StringIndex on it is a "child". It does one thing. It extracts the value of the indexed (capture group) from the parent, and sets that as the string value of the measure.
Ok, but in this case, if I added a StringIndex=1 option to [MeasureReviews], is it a parent or a child measure? Because it has both, a RegExp and a StringIndex.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

balala wrote: November 20th, 2018, 2:13 pm No, I don't. What I meant was that if I use the code posted by you here:

I get reviews_available":19,, even if I add the StringIndex=1 option to [MeasureReviews] (obviously I replaced the URL option of [MeasureSite]).
To do this with the usual "parent / child" approach, it would look like:

Code: Select all

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

[Variables]

[MeasureSite]
Measure=Webparser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)reviews_available":(.*),

[MeasureReviews]
Measure=Webparser
URL=[MeasureSite]
StringIndex=1

[MeterResult]
Meter=String
MeasureName=MeasureReviews
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

To use one measure as both "parent" and "child", it would look like:

Code: Select all

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

[Variables]

[MeasureReviews]
Measure=WebParser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)reviews_available":(.*),
StringIndex=1

[MeterResult]
Meter=String
MeasureName=MeasureReviews
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Little Help with RegExp / Search String showing in output

Post by jsmorley »

balala wrote: November 20th, 2018, 2:17 pm Ok, but in this case, if I added a StringIndex=1 option to [MeasureReviews], is it a parent or a child measure? Because it has both, a RegExp and a StringIndex.
In a sense, it ends up as a "child" measure, as the final string value will be the (capture) based on the StringIndex. It plays both roles however, as it uses the RegExp to create the "match" and index the captures, then turns around and uses the index to set the final string value.
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Little Help with RegExp / Search String showing in output

Post by balala »

jsmorley wrote: November 20th, 2018, 2:22 pm In a sense, it ends up as a "child" measure, as the final string value will be the (capture) based on the StringIndex. It plays both roles however, as it uses the RegExp to create the "match" and index the captures, then turns around and uses the index to set the final string value.
Yep, both code posted above are good, understandable and work as they should.
However my question is still the same (but it seems we didn't understand each other): I have the following code:

Code: Select all

[MeasureSite]
Measure=Webparser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)^(.*)$

[MeasureReviews]
Measure=Webparser
URL=[MeasureSite]
RegExp=(?siU)reviews_available":(.*),
StringIndex=1

[MeterResult]
Meter=String
MeasureName=MeasureReviews
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
No matter if the StringIndex is added or not to [MeasureReviews], I get the same result: not just 19, but reviews_available":19,. What I'd expect is to get reviews_available":19, if I don't set a StringIndex to [MeasureReviews], but get 19, if I add a StringIndex=1 option to it. but something else is going on.
I'm sorry to bother you, but still isn't clear to me.