It is currently March 28th, 2024, 12:53 pm

WebParser now supports Dynamic Variables

Changes made during the Rainmeter 3.0 beta cycle.
Post Reply
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

WebParser now supports Dynamic Variables

Post by jsmorley »

We are very excited to announce that we have added the ability to use dynamic variables with WebParser. There are a few very important caveats that I will go over in some detail below, but this is a huge step forward in how WebParser works.

Some examples of what this opens up are:

Have an RSS feed skin that you can change from feed site to feed site without having to use !WriteKeyValue or !Refresh the skin.

Page through large RSS feeds, without needing tons of "child" measures.

Dynamically change the location code in a weather skin, to enable multiple locations in a single skin. Again without having to use !WriteKeyValue and !Refresh.

Have the result of parsing one site provide all or part of the URL option for a second WebParser "parent". For instance, you might parse Site A for a user name, and then use that name to find and parse game statistics from Site B.

Some important things to understand:

1) If you want to use a dynamic #VariableName# on a WebParser measure, the measure must include DynamicVariables=1, just like any other measure. If you use !SetOption to change a WebParser option, then DynamicVariables=1 is not required, also just like any other measure.

2) WebParser uses UpdateRate to determine how often the plugin should actually access the site or file. While you can now dynamically change any option on a WebParser measure, the plugin will not use the changes and access the site again until the next UpdateRate is reached. Just using !Update or !UpdateMeasure will NOT override the UpdateRate.

In order to have a dynamic change make WebParser parse the site "right now", you will use the !CommandMeasure bang with the "parent" WebParser measure as the first parameter, and Update as the second. Don't forget that the default for UpdateRate is 600, so a dynamic change can take up to that long to "happen" if you don't force it with !CommandMeasure.

Example:

LeftMouseUpAction=[!SetOption WebMeasure URL "http://SomeNewSite.com"][!CommandMeasure WebMeasure Update]

3) If you dynamically change an option on a "child" WebParser measure that depends on a "parent" measure, (like StringIndex for instance) you MUST use !CommandMeasure with "Update", targeting the "parent" WebParser measure. The values of child WebParser measures are a function of the parent measure, and are only updated when the parent is. You should never use !CommandMeasure on a "child" measure, as it won't do anything.

4) The way that WebParser has always worked is that you parse a site and create StringIndex numbers with the "parent" measure, then pick off the individual values by StringIndex number in "child" measures. This has not changed.

Code: Select all

[MeasureParent]
Measure=Plugin
Plugin=WebParser
URL=http://SomeSite.com
RegExp=(?siU)<title>(.*)</title>

[MeasureChild]
Measure=Plugin
Plugin=WebParser
URL=[MeasureParent]
StringIndex=1
However, if you want to dynamically use the actual current value of any measure in the URL option of a WebParser measure, you must tell WebParser to use that measure as a "section variable" rather than the normal reference to a "parent". This is done by preceding the name of the measure in braces with the "&" character.

Code: Select all

[MeasureParent]
Measure=Plugin
Plugin=WebParser
URL=http://SomeSite.com
RegExp=(?siU)<UserName>(.*)</UserName>
StringIndex=1

[MeasureSecondParent]
Measure=Plugin
Plugin=WebParser
URL=http://SomeSite.com/[&MeasureParent]
RegExp=(?siU)<Ranking>(.*)</Ranking>
DynamicVariables=1

[MeasureChild]
Measure=Plugin
Plugin=WebParser
URL=[MeasureSecondParent]
StringIndex=1
Some example skins:

Here are a few example skins you can install and take a look at to see how to dynamically interact with WebParser, and how those caveats described above factor in.

1) Use the value of one parent in the URL option of a second parent. This demonstrates how you would use the [&MeasureName] variant to tell WebParser to use the value of another WebParser measure as a "section variable" in the URL option.

DynaSite_1.0.rmskin

Image


2) Dynamically change the location code in a weather skin, to have a single skin with multiple weather locations.

DynaWeather_1.0.rmskin

Image

Image


3) Dynamically "page" through a large RSS feed.

DynaFeed_1.0.rmskin

Image


Taking a look at the actual code in these skins will show some ways to make things "dynamic" with WebParser. We are really pleased with this change, and hope we see some very clever uses in the near future.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: WebParser now supports Dynamic Variables

Post by MerlinTheRed »

Yes! I love you.
User avatar
thatsIch
Posts: 446
Joined: August 7th, 2012, 9:18 pm

Re: WebParser now supports Dynamic Variables

Post by thatsIch »

this is a huge milestone! banzai!
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: WebParser now supports Dynamic Variables

Post by moshi »

jsmorley wrote: In order to have a dynamic change make WebParser parse the site "right now", you will use the !CommandMeasure bang with the "parent" WebParser measure as the first parameter, and Update as the second. Don't forget that the default for UpdateRate is 600, so a dynamic change can take up to that long to "happen" if you don't force it with !CommandMeasure.
i noticed that this [!CommandMeasure Whatever Update] does not seem to work when UpdateDivider=-1 is set. is this intentional? is there a way to update a dynamic webparser measure with UpdateDivider=-1?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WebParser now supports Dynamic Variables

Post by jsmorley »

The !CommandMeasure is about overriding UpdateRate in the plugin. You can use !UpdateMeasure to force a normal measure update. So in that case, use both.
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: WebParser now supports Dynamic Variables

Post by StArL0rd84 »

Making a version checker for my skin.

Why can't i use a measure as a variable in the parser?

[mNextVersion]
Measure=Calc
Formula=#VersionNumber#+1
DynamicVariables=1

[mSkinVersion]
Measure=Plugin
Plugin=WebParser
UpdateRate=3600
Url=http://#DevArtUserName#.deviantart.com/art/#SkinName#-[mNextVersion]-#UploadID#
RegExp="(?siU)<a href="http://#DevArtUserName#.deviantart.com/art/#SkinName#-[mNextVersion]-#UploadID#" data-ga_click_event="{"category":"Deviation","action":"description_title","nofollow":0}">#SkinName# (.*)</a>"
StringIndex=1
FinishAction=[!ShowMeter Item2]
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser now supports Dynamic Variables

Post by balala »

StArL0rd84 wrote:Why can't i use a measure as a variable in the parser?
I'm not sure you are in the corresponding section to ask a such question.

But to reply you, because, according to the last sentence here,
If you want to use the current value of a measure in a dynamic way as a Section Variable, rather than as a reference to a "parent" WebParser measure, you must prefix the name of the measure with the & character.
So, add that character, in the measure name, in the URL option: Url=http://#DevArtUserName#.deviantart.com/art/#SkinName#-[[color=#FF0000]&[/color]mNextVersion]-#UploadID#
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy
Contact:

Re: WebParser now supports Dynamic Variables

Post by fonpaolo »

From the Rainmeter Docs:
"If you want to use the current value of a measure in a dynamic way as a Section Variable, rather than as a reference to a "parent" WebParser measure, you must prefix the name of the measure with the & character.
URL=http://SomeSite.com\[&WebMeasure]"
edit: beaten by balala. ;-)
User avatar
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: WebParser now supports Dynamic Variables

Post by StArL0rd84 »

Sorry for posting in the wrong place.

Anyways now that we are here...

I replaced mNextVersion with &mNextVersion in the URL and RegExp.
Got a matching error in the log. ( RegExp matching error (-1) )

Replaced mNextVersion with &mNextVersion in the measure name too.
Got rid of the error in the log but still no cigar.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser now supports Dynamic Variables

Post by balala »

StArL0rd84 wrote:I replaced mNextVersion with &mNextVersion in the URL and RegExp.
Replace it just in URL, but not in RegExp and try again.
Post Reply