It is currently April 18th, 2024, 2:36 pm

Workaround for Dynamic Variables in WebParser Plugin

Tips and Tricks from the Rainmeter Community
Terrorlone
Posts: 6
Joined: August 15th, 2011, 12:08 pm

Workaround for Dynamic Variables in WebParser Plugin

Post by Terrorlone »

Hi everyone, I'm new here. I really love rainmeter so I devoted some time into it and design several cool skins for myself. Here's a trick I found to be really useful; maybe it's not new or advanced, but it's a good one anyway.

Here's the situation: I'm using WebParser to get something I need, however the URL is not a fixed one, but also from another webpage which I'll need to read it using WebParser first.
For example, say I want to show the content of the latest post on some forum, but the URL of that post is not fixed, I will need to obtain it from the forum main page first.

Now here's the problem: WebParser (or any other Plugin) doesn't support dynamic variables! So even if I managed to get the URL string using the first WebParser (say [mURL]), the second WebParser (say [mLastestPost]) is not going to reach for the correct URL even if I use variables in the Url option!
Well, someone may say use our new weapon, !SetOption... but no, it also doesn't work on Plugins!

So here's my method for overcoming the problem.

Code: Select all

[Variables]
URL=...

[mGetURL]
Measure=Plugin
Plugin=WebParser.dll
Url=...
RegExp=....
Disabled=0
FinishAction=!Execute [!Update][!WriteKeyValue Variables "URL" "[mURL]"][!WriteKeyValue mGetURL Disabled 1][!WriteKeyValue mLatestPost Disabled 0][!Refresh]

[mURL]
Measure=Plugin
Plugin=WebParser.dll
Url=[mGetURL]
StringIndex=...
Disabled=0

[mLatestPost]
Measure=Plugin
Plugin=WebParser.dll
Url=#URL#
RegExp=....
Disabled=1
You see what happen? After I successfully obtained the URL string, I use the magical !WriteKeyValue bang to set it as a variable, and refresh the skin! Also I switch the "Disabled" option of the two measures, so that after the URL is updated, the [mGetURL] measure won't bother things again. Notice that I put a !Update bang first, so that the [mURL] will update immediately.

But here comes another question: how do I, say after a period of time, update the URL? Since [mGetURL] is now disabled...

Well, simple! Just setup a counter like this:

Code: Select all

[mRefreshCounter]
Measure=Calc
Formula=mRefreshCounter+1
IfAboveValue=1000
IfAboveAction=!Execute [!WriteKeyValue mGetURL Disabled 0][!WriteKeyValue mLatestPost Disabled 1][!Refresh]
So that after 1000 units of time, the "Disabled" option will be switched back, and get a new URL for the latest post!

You can also use the same trick with more than one step of infomation getting. For example, in my own skin, I first obtain the URL of a second page from the main page, and then get the URL of a particular image from that second page, and then show that image! Pretty cool, isn't it?

Thanks for reading :welcome:
Terrorlone
Posts: 6
Joined: August 15th, 2011, 12:08 pm

Re: Tricks with !WriteKeyValue and WebParser

Post by Terrorlone »

By the way, suppose that you only need to obtain the URL once, then here's a way you could slightly simplify the approach:

Code: Select all

[Variables]
URL=...

[mGetURL]
Measure=Plugin
Plugin=WebParser.dll
Url=...
RegExp=....
Disabled=1
FinishAction=!Execute [!Update][!WriteKeyValue Variables "URL" "[mURL]"][!Refresh]

[mURL]
Measure=Plugin
Plugin=WebParser.dll
Url=[mGetURL]
StringIndex=...
Disabled=0

[mLatestPost]
Measure=Plugin
Plugin=WebParser.dll
Url=#URL#
RegExp=....

[mRefreshCounter]
Measure=Calc
Formula=mRefreshCounter+1
IfAboveValue=1000
IfAboveAction=!Execute [!ToggleMeasure mGetURL][!Update]

The good thing about this is that there's no need to switch the "Disabled" option, and the !Refresh bang is executed only once. The downside of this method is that during the very first time this skin is loaded, you won't see anything until the auto-refresh, unless you manually entered the Url variable. But that shouldn't be a problem if the skin is just for yourself, not for distribution.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Tricks with !WriteKeyValue and WebParser

Post by poiru »

You don't need the [mURL] measure. Here is a slightly simplified version:

Code: Select all

[Variables]
URL=...

[mGetURL]
Measure=Plugin
Plugin=WebParser.dll
Url=...
RegExp=....
StringIndex=...
FinishAction=!Execute [!WriteKeyValue Variables "URL" "[mGetURL]"][!WriteKeyValue mGetURL Disabled 1][!Refresh]
Disabled=0

[mLatestPost]
Measure=Plugin
Plugin=WebParser.dll
Url=#URL#
RegExp=....

[mRefreshCounter]
Measure=Calc
Formula=mRefreshCounter+1
IfAboveValue=1000
IfAboveAction=!Execute [!WriteKeyValue mGetURL Disabled 0][!Refresh]
As to your second post, [mGetURL] will be disabled until the 1000th update cycle ;)
Terrorlone
Posts: 6
Joined: August 15th, 2011, 12:08 pm

Re: Tricks with !WriteKeyValue and WebParser

Post by Terrorlone »

poiru wrote:You don't need the [mURL] measure.
I know someone will ask this. The reason why I put a [mURL] there in this demonstration is because I use [mGetURL] measure to obtain not just one, but two strings. Of course you don't need it if you only need one string.
poiru wrote:As to your second post, [mGetURL] will be disabled until the 1000th update cycle.
That's what I'm saying in the "downside" part.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Tricks with !WriteKeyValue and WebParser

Post by poiru »

Terrorlone wrote:I know someone will ask this. The reason why I put a [mURL] there in this demonstration is because I use [mGetURL] measure to obtain not just one, but two strings. Of course you don't need it if you only need one string.
Yeah, both examples are good to have :)
Terrorlone wrote:That's what I'm saying in the "downside" part.
Ah, sorry, missed that bit of your post.
kylejdb
Posts: 7
Joined: August 17th, 2011, 3:28 pm

Re: Tricks with !WriteKeyValue and WebParser

Post by kylejdb »

this helps a lot with two separate things ive been tediously working on. thanks for the great post Terrorlone!
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Tricks with !WriteKeyValue and WebParser

Post by KreAch3R »

It has also helped me in one skin I made, so, thank you very much for your tutorial. :)
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
fragrant.monkey
Posts: 51
Joined: September 18th, 2010, 1:03 am

Re: Workaround for Dynamic Variables in WebParser Plugin

Post by fragrant.monkey »

This is exactly what I came here to search for tonight... I was about to post and ask for suggestions!!!

I haven't even incorporated yet, but I know it's the answer to my conundrum. Thanks so much for sharing!

:rosegift:
fragrant.monkey :: deviantArt: aka snuffleupagus | coding: ThemeSaver for RocketDock | musician: Madera Dulce