It is currently May 3rd, 2024, 6:49 pm

Writekeyvalue and webparser

Get help with creating, editing & fixing problems with skins
Sweetness
Posts: 21
Joined: August 18th, 2011, 2:03 am

Writekeyvalue and webparser

Post by Sweetness »

Hi i'm trying to have a StringIndex that is returned from RegExp to right to a Variable.
I used this post as a referance http://rainmeter.net/forum/viewtopic.php?f=15&t=9307
just can`t get it to work. must be missing something.
i created a quick skin to test

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
debug=1
LeftMouseDoubleClickAction=!Execute [!WriteKeyValue Variables keytest1 #keytest2#][!WriteKeyValue Variables keytest2 #keytest1#][!Refresh]


[Variables]
URL=
keytest1=BBB
keytest2=AAA
get=.* label="(.*)"/>
 
[MeterBackground]
 Meter=Image
 W=300
 H=155
 SolidColor=70,130,180,255
 
[sText]
FontColor=0,0,0,255
FontFace=Trebuchet MS
FontSize=12

[mGetURL]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://rainmeter.net/forum/feed.php
RegExp="(?siU)<title>(.*)<\/title>#get##get#"
UpdateRate=3600
StringIndex=1



[MeasureItem1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[mGetURL]
StringIndex=1
FinishAction=!Execute !RainmeterEnableMeasure MeasureItem2

[MeasureItem2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[mGetURL]
StringIndex=2
DynamicVariables=1
FinishAction=!Execute [!WriteKeyValue Variables "URL" "MeasureItem1"][!Refresh]
Disabled=1


[MeterItem1]
Meter=String
MeterStyle=sText
MeasureName=MeasureItem1
X=5
Y=5
ClipString=0


[MeterItem2]
Meter=String
MeterStyle=sText
MeasureName=MeasureItem2
X=5
Y=20
ClipString=0


[MeterItem3]
Meter=String
MeterStyle=sText
X=5
Y=40
ClipString=0
text=#keytest1#

[MeterItem4]
Meter=String
MeterStyle=sText
X=5
Y=60
ClipString=0
text=#keytest2#

[MeterItem5]
Meter=String
MeterStyle=sText
X=5
Y=80
ClipString=0
text=value is #URL#
first line is a feed (which enables line two)
line 2 is another feed which should write to a variable
line 3 and 4 is just a test. If double clicked it should toggle (just to make sure i was doing something right)
line 4 should show the variable that line two wrote.
Thanks
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Writekeyvalue and webparser

Post by Kaelri »

There are several overlapping issues with this skin, so I'll try to deal with them one at a time.

First, look at what you're doing with these two measures:

Code: Select all

[MeasureItem1]
...
FinishAction=!Execute !RainmeterEnableMeasure MeasureItem2

[MeasureItem2]
...
FinishAction=!Execute [!WriteKeyValue Variables "URL" "MeasureItem1"][!Refresh]
[MeasureItem1] enables [MeasureItem2], and [MeasureItem2] refreshes the skin, starting the process over again. If this worked the way it's written, you would end up with an infinite loop, in which the skin would be constantly refreshing itself.

Second, this -

Code: Select all

[MeasureItem2]
Measure=Plugin
...
DynamicVariables=1
FinishAction=!Execute [!WriteKeyValue Variables "URL" "MeasureItem1"][!Refresh]
- won't work, because you can't use dynamic variables in Plugin measures.

Third, there are a couple of syntax errors. Although these may seem like minor differences, it's very important that they're correct, or else Rainmeter won't understand what you want it to do.

The first error is here:

Code: Select all

FinishAction=!Execute !RainmeterEnableMeasure MeasureItem2
!Execute strings need to place each separate comment inside brackets, like this:

Code: Select all

FinishAction=!Execute [!RainmeterEnableMeasure MeasureItem2]
The second syntax error is here:

Code: Select all

FinishAction=!Execute [!WriteKeyValue Variables "URL" "MeasureItem1"][!Refresh]
Unless "MeasureItem1" is in [brackets], this bang would not send the measure value, but rather the actual, literal text, "MeasureItem1".

Code: Select all

FinishAction=!Execute [!WriteKeyValue Variables "URL" "[MeasureItem1]"][!Refresh]
Now, here's what you probably want to do:

Code: Select all

[Variables]
...
WriteNewVariable=1

[MeasureItem1]
...
FinishAction=!Execute [!EnableMeasure MeasureWriteKeyValue]

[MeasureWriteKeyValue]
Measure=Calc
Disabled=1
DynamicVariables=1
Formula=#WriteNewVariable#
IfEqualValue=1
IfEqualAction=!Execute [!WriteKeyValue Variables WriteNewVariable 0][!WriteKeyValue URL "[MeasureItem1]"][!Refresh]
When [MeasureItem1] finishes, it will activate the new measure, [MeasureWriteKeyValue]. The new measure will then check to see if the variable "WriteNewVariable" is 1. If so, it will write the WebParser string to a variable and refresh the skin. It will also change "WriteNewVariable" to 0, so that this action only happens once, not over and over again.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Writekeyvalue and webparser

Post by jsmorley »

I really think a "Tips & Tricks" as a sticky or on the main site might be good for this topic... It comes up over and again.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Writekeyvalue and webparser

Post by Kaelri »

jsmorley wrote:I really think a "Tips & Tricks" as a sticky or on the main site might be good for this topic... It comes up over and again.
I suppose this thread (which the OP is referencing) is a decent template. Should I perhaps sticky it and rename it something like "Changing WebParser Options without Dynamic Variables"?
Sweetness
Posts: 21
Joined: August 18th, 2011, 2:03 am

Re: Writekeyvalue and webparser

Post by Sweetness »

Thanks for the help.
I understand everything you are saying and the way it should flow.

But I must be missing something here. Just not working.
Please have a look.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
debug=1
LeftMouseDoubleClickAction=!Execute [!WriteKeyValue Variables WriteNewVariable 1][!Refresh]

[Variables]
URL=
get=.* label="(.*)"/>
WriteNewVariable=1

[MeterBackground]
Meter=Image
W=300
H=155
SolidColor=70,130,180,255

[sText]
FontColor=0,0,0,255
FontFace=Trebuchet MS
FontSize=12

[mGetURL]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=http://rainmeter.net/forum/feed.php
RegExp="(?siU)<title>(.*)<\/title>#get##get#"
UpdateRate=3600
StringIndex=1

[MeasureItem1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
URL=[mGetURL]
StringIndex=1
FinishAction=!Execute [!EnableMeasure MeasureWriteKeyValue]

[MeasureWriteKeyValue]
Measure=Calc
Disabled=1
DynamicVariables=1
Formula=#WriteNewVariable#
IfEqualValue=1
IfEqualAction=!Execute [!WriteKeyValue Variables WriteNewVariable 0][!WriteKeyValue URL "[MeasureItem1]"][!Refresh]

[MeterItem1]
Meter=String
MeterStyle=sText
MeasureName=MeasureItem1
X=5
Y=5
ClipString=0

[MeterItem5]
Meter=String
MeterStyle=sText
X=5
Y=25
ClipString=0
text=value is #URL#
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Writekeyvalue and webparser

Post by Kaelri »

Only two small problems this time. :)

First, it turns out that "FinishAction" only works on the primary WebParser measure - [mGetURL], in this case, rather than [MeasureItem1]. I actually didn't realize this until I tested your skin just now.

Second, the !WriteKeyValue command requires that you specify the [Variables] section name:

Code: Select all

[!WriteKeyValue Variables URL "[MeasureItem1]"]
Once you fix those issues, it should work fine.
Sweetness
Posts: 21
Joined: August 18th, 2011, 2:03 am

Re: Writekeyvalue and webparser

Post by Sweetness »

Thank-you Kaelri for the help. Works fine.

I have one question about this.
First, it turns out that "FinishAction" only works on the primary WebParser measure - [mGetURL], in this case, rather than [MeasureItem1].
Can there be a possibility that the [MeasureWriteKeyValue] measure does it's caculation before the [MeasureItem1] measure get's the value from [mGetURL]?
Because the primary measure is the one that is activating the [MeasureWriteKeyValue] measure. Can this be a problem?
If i have a more complicated skin and i need (for argument's sake) 4 URL variables to write.
I have [MeasureWriteKeyValue1]...[MeasureWriteKeyValue4] can [MeasureItem1]..[MeasureItem4] win the race?

But anyways, I'll move forward with what you have helped me on.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Writekeyvalue and webparser

Post by Kaelri »

Sweetness wrote:Can there be a possibility that the [MeasureWriteKeyValue] measure does it's caculation before the [MeasureItem1] measure get's the value from [mGetURL]?
Because the primary measure is the one that is activating the [MeasureWriteKeyValue] measure. Can this be a problem?
If i have a more complicated skin and i need (for argument's sake) 4 URL variables to write.
I have [MeasureWriteKeyValue1]...[MeasureWriteKeyValue4] can [MeasureItem1]..[MeasureItem4] win the race?

But anyways, I'll move forward with what you have helped me on.
In this case, it doesn't matter what order the measures update in. The "!EnableMeasure" bang only takes effect on the skin's next Update cycle - usually 1 second later. So, in effect, this method has a built-in delayed action feature. There is no way for the [MeasureWriteKeyValueX] to run before [MeasureItemX] has been updated.