I wondered if anyone else might find it useful to have WebParser have a ErrorAction that is executed when the parsing fails for some reason or any other problem is met.
In my particular case I do a FinishAction to run a script that sets some variables based on the result of the parsing. When the parsing fails (e.g. because there is no internet connection) I want to be able to take appropriate actions like displaying a error image or cleaning up the skin so it doesn't look weird when the text that was supposed to come from the parser isn't there. For example a weather skin should not display Temperature: ° when parsing fails.
Apart from that: I would find it handy if WebParser offered an option to check the provided URL more often if it can't connect (so you don't have to refresh the skin when you just re-established your internet connection).
If there is already a reliable and elegant way of doing any of this, please enlighten me
It is currently April 28th, 2024, 5:33 pm
[Suggestion] WebParser: ErrorAction
-
- Rainmeter Sage
- Posts: 889
- Joined: September 6th, 2011, 6:34 am
[Suggestion] WebParser: ErrorAction
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [Suggestion] WebParser: ErrorAction
Something like this will work for the first bit, although I'm not sure "elegant" is a word I would use... However, setting ErrorString to a numeric value and then IfAction'ing it sorta does an "IfErrorAction".
[Rainmeter]
Update=1000
DynamicWindowSize=1
[MeasureWeb]
Measure=Plugin
Plugin=WebParser.dll
Url=file://#CURRENTPATH#test.txt
RegExp="(?siU)<temp>(.*)</temp>"
UpdateDivider=1
UpdateRate=300
StringIndex=1
ErrorString="-999"
IfEqualValue=-999
IfEqualAction=!SetOption Meter1 Text "Parsing Error"
IfAboveValue=-999
IfAboveAction=!SetOption Meter1 Text "Temperature: %1°"
[Meter1]
Meter=String
MeasureName=MeasureWeb
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
Text=" "
Note: ErrorString will also work on "child" WebParser measures as the "Not enough substrings" that will be caused will also allow ErrorString to be set. So you could have different "actions" to take on each if you want.
[Rainmeter]
Update=1000
DynamicWindowSize=1
[MeasureWeb]
Measure=Plugin
Plugin=WebParser.dll
Url=file://#CURRENTPATH#test.txt
RegExp="(?siU)<temp>(.*)</temp>"
UpdateDivider=1
UpdateRate=300
StringIndex=1
ErrorString="-999"
IfEqualValue=-999
IfEqualAction=!SetOption Meter1 Text "Parsing Error"
IfAboveValue=-999
IfAboveAction=!SetOption Meter1 Text "Temperature: %1°"
[Meter1]
Meter=String
MeasureName=MeasureWeb
FontSize=13
FontColor=255,255,255,255
SolidColor=0,0,0,1
Text=" "
Note: ErrorString will also work on "child" WebParser measures as the "Not enough substrings" that will be caused will also allow ErrorString to be set. So you could have different "actions" to take on each if you want.
-
- Posts: 5
- Joined: September 21st, 2011, 10:39 pm
Re: [Suggestion] WebParser: ErrorAction
Hey JS,
I just tried your suggestion above but I can't get it to work.
I'm writing my own µTorrent skin and would like to clear the data if the user exits µTorrent. As it is now, (and the existing similar skins I've inspected), the last output from the WebParser "sticks". The log throws the error message "A connection with the server could not be established".
This is what I tried:
Any thoughts?
I just tried your suggestion above but I can't get it to work.
I'm writing my own µTorrent skin and would like to clear the data if the user exits µTorrent. As it is now, (and the existing similar skins I've inspected), the last output from the WebParser "sticks". The log throws the error message "A connection with the server could not be established".
This is what I tried:
Code: Select all
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1
Url=#URL#
RegExp="(?siU)\"torrents\": \[\n\n(.*?\]\])"
StringIndex=1
ErrorString="-999"
IfEqualValue=-999
; IfEqualAction=!Execute [!SetVariable hideTorrent1 1][!SetVariable hideTorrent2 1][!SetVariable hideTorrent3 1][!SetVariable hideTorrent4 1]
IfEqualAction=!Execute [!RainmeterHide]
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [Suggestion] WebParser: ErrorAction
Try adding ForceReload=1 to the webparser measure.d00b wrote:Hey JS,
I just tried your suggestion above but I can't get it to work.
I'm writing my own µTorrent skin and would like to clear the data if the user exits µTorrent. As it is now, (and the existing similar skins I've inspected), the last output from the WebParser "sticks". The log throws the error message "A connection with the server could not be established".
This is what I tried:Any thoughts?Code: Select all
Measure=Plugin Plugin=Plugins\WebParser.dll UpdateRate=1 Url=#URL# RegExp="(?siU)\"torrents\": \[\n\n(.*?\]\])" StringIndex=1 ErrorString="-999" IfEqualValue=-999 ; IfEqualAction=!Execute [!SetVariable hideTorrent1 1][!SetVariable hideTorrent2 1][!SetVariable hideTorrent3 1][!SetVariable hideTorrent4 1] IfEqualAction=!Execute [!RainmeterHide]
-
- Posts: 5
- Joined: September 21st, 2011, 10:39 pm
Re: [Suggestion] WebParser: ErrorAction
Nope. No difference. The IfEqualAction is not executed.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: [Suggestion] WebParser: ErrorAction
Yeah, this is going to take a different approach. ErrorString is really about the regular expression / PCRE "parser" failing to parse the output, and I'm not sure it is ever getting to that point if the connection fails in general. Normally when a site on the web you try to connect to is down or the url is wrong, you get some 404 return from your ISP and a "connection" is still made. Then the RegExp fails and ErrorString is set. With localhost / 127.0.0.1 you will just not connect at all if the local http server is not running.d00b wrote:Nope. No difference. The IfEqualAction is not executed.
What I did in my uTorrent skin is:
[MeasureProcessPID]
Measure=Plugin
Plugin=Perfmon.dll
PerfMonObject="Process"
PerfMonCounter="ID Process"
PerfMonInstance="uTorrent"
PerfMonDifference=0
UpdateDivider=2
[CalcTranslatePIDToRunningState]
Measure=Calc
Formula=MeasureProcessPID > 0 ? 1 : 0
IfAboveValue=0
IfAboveAction=!Execute [!EnableMeasure MeasureWebUI]
IfEqualValue=0
IfEqualAction=!Execute [!DisableMeasure MeasureWebUI]]
What this does is check to see if the process "uTorrent" is running in Windows. If it is, it enables the WebParser measure (which is set to Disabled=1 initially) and if it is not it disables it. You can of course (and in fact I do) stack other [!Bang] stuff on that line to hide or show meters/meter groups, ect. as needed.
-
- Posts: 5
- Joined: September 21st, 2011, 10:39 pm
Re: [Suggestion] WebParser: ErrorAction
Yeah, when you put it like that it makes perfect sense. Calling localhost if none is running will never produce a connection, hence no response error code either. I tried your workaround using the Perfmon plugin and it worked a charm. Much obliged!
I really enjoy passing time tinkering with rainmeter, it's lots of fun. Again, thanks for all your help.
I really enjoy passing time tinkering with rainmeter, it's lots of fun. Again, thanks for all your help.