WebParser now supports Dynamic Variables

Changes made during the Rainmeter 3.0 beta cycle.
User avatar

WebParser now supports Dynamic Variables

August 4th, 2013, 2:57 pm
jsmorley
Developer   [15497 posts]

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

Re: WebParser now supports Dynamic Variables

August 4th, 2013, 4:56 pm
MerlinTheRed
Rainmeter Sage   [911 posts]

Yes! I love you.
User avatar

Re: WebParser now supports Dynamic Variables

August 5th, 2013, 11:14 am
thatsIch
   [457 posts]

this is a huge milestone! banzai!
User avatar

Re: WebParser now supports Dynamic Variables

August 15th, 2013, 8:08 am
moshi
   [1852 posts]

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

Re: WebParser now supports Dynamic Variables

August 15th, 2013, 11:27 am
jsmorley
Developer   [15497 posts]

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

Re: WebParser now supports Dynamic Variables

February 6th, 2017, 4:50 pm
StArL0rd84
   [135 posts]

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="{&quot;category&quot;:&quot;Deviation&quot;,&quot;action&quot;:&quot;description_title&quot;,&quot;nofollow&quot;:0}">#SkinName# (.*)</a>"
StringIndex=1
FinishAction=[!ShowMeter Item2]
DynamicVariables=1
User avatar

Re: WebParser now supports Dynamic Variables

February 6th, 2017, 5:16 pm
balala
Rainmeter Sage   [4058 posts]

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#-[&mNextVersion]-#UploadID#
User avatar

Re: WebParser now supports Dynamic Variables

February 6th, 2017, 5:17 pm
fonpaolo
Moderator   [1056 posts]

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

Re: WebParser now supports Dynamic Variables

February 6th, 2017, 5:47 pm
StArL0rd84
   [135 posts]

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

Re: WebParser now supports Dynamic Variables

February 6th, 2017, 6:43 pm
balala
Rainmeter Sage   [4058 posts]

StArL0rd84 wrote:I replaced mNextVersion with &mNextVersion in the URL and RegExp.

Replace it just in URL, but not in RegExp and try again.

Return to “Rainmeter 3.0”



Who is online

Users browsing this forum: No registered users and 0 guests