It is currently December 4th, 2020, 5:20 pm

Website status checking

Get help with installing and using Rainmeter.
Jimmy401
Posts: 6
Joined: September 9th, 2020, 7:31 am

Re: Website status checking

Post by Jimmy401 »

Guess there's no way of avoiding this...
I realised it was my luascript triggering on load / refresh running some code I was using for testing :oops:

It's all good and working as I need it to now :D

Thank you everyone for the assist!
User avatar
Yincognito
Posts: 2934
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Website status checking

Post by Yincognito »

Jimmy401 wrote: September 9th, 2020, 10:01 am now that it's only triggering once on load, I will probably look at re-writing my lua... perhaps there is a more easier / efficient way to do this.
Just so you know, there isn't an absolute need to use Lua to write that log (unless you have more complex things that you want to be written there). One can use the !WriteKeyValue bang to pretty much do the same, and then optionally either @Include the file in the skin so you can have all those variables at your disposal (maybe you want to do other things with them) or parse the log file itself to get its contents (obviously, the parsing can be further refined). In the sample below I chose the latter, as it doesn't involve the need to refresh the skin to "update" the parsed content (like using an @Include does). The log file can be viewed by left clicking, by the way:

Skin:

Code: Select all

[Variables]
LogFile=site.log
LocalLog=#CURRENTPATH##LogFile#
webURL=https://www.google.com
Font=Arial
FCL=FFFFFF
FCD=13A7C7
DownFF=FF0000
WaitFF=FFFF00
GoodFF=00FF00
FSize=14
State=Wait

[Rainmeter]
Update=1000

---Measures---

[WebMeasure]
Measure=Webparser
URL=#webURL#
RegExp=(?siU)<title>(.*)</title>
StringIndex=1
UpdateDivider=600
UpdateRate=1
OnUpdateAction=[!SetVariable State "In Progress"][!UpdateMeasureGroup WebGroup]
FinishAction=[!SetVariable State "Finished"][!UpdateMeasureGroup WebGroup]
OnConnectErrorAction=[!SetVariable State "Connect Error"][!UpdateMeasureGroup WebGroup]
DynamicVariables=1

[Time]
Measure=Time
Format=D%Y-%m-%dT%H:%M:%S

[WebStatus]
Group=WebGroup
Measure=String
String="#State#, [WebMeasure]"
UpdateDivider=-1
RegExpSubstitute=1
Substitute="(?siU)^In Progress, .*$":"Wait","(?siU)(?:^Connect Error, .*$|^Finished, $)":"Down","(?siU)^Finished, Google$":"Good"
IfMatch=^Wait$
IfNotMatchAction=[!WriteKeyValue Variables "[Time]" "[WebStatus]" "#LocalLog#"][!CommandMeasure LogFile "Update"]
OnUpdateAction=[!Redraw]
DynamicVariables=1

[LogFile]
Measure=WebParser
URL="file://#LocalLog#"
CodePage=1200
RegExp=(?siU)^(.*)$
StringIndex=1
FinishAction=[!UpdateMeter *][!Redraw]
OnConnectErrorAction=[!UpdateMeter *][!Redraw]
OnRegExpErrorAction=[!UpdateMeter *][!Redraw]
DynamicVariables=1

---Styles---

[StyleLabel]
Meter=String
FontFace=#Font#
FontColor=#FCD#
FontSize=#FSize#
FontEffectColor=20,20,20,125
StringEffect=Shadow
StringAlign=Left
Antialias=1

---Meters---

[WebsiteLabel]
Meter=String
MeterStyle=StyleLabel
X=0
Text=Google:
LeftMouseUpAction=[!ToggleMeter Log][!Redraw]
DynamicVariables=1

[WebMeter]
Meter=String
MeterStyle=StyleLabel
X=5R
FontColor=[#[&WebStatus]FF]
MeasureName=WebStatus
Text=%1
DynamicVariables=1

[Log]
Hidden=1
Meter=String
MeterStyle=StyleLabel
MeasureName=LogFile
Y=5R
Text=Log:#CRLF#%1
DynamicVariables=1
Site.log (encoded as UCS-2 LE BOM in Notepad++, in the current skin folder; initially empty, presented here for demonstration purposes):

Code: Select all

[Variables]
D2020-09-09T18:11:05=Good
D2020-09-09T18:14:42=Good
D2020-09-09T18:18:33=Good
D2020-09-09T18:19:08=Down
The IfMatchMode=1 can be safely added to [WebStatus], since its UpdateDivider is -1, thus updated only on demand, when [WebMeasure] is updated as well. Controlling [WebMeasure]'s update rate from the UpdateDivider and keeping the UpdateRate option to 1 is needed for the OnUpdateAction to trigger right before the site is parsed. The FontColor=[#[&WebStatus]FF] line makes use of the nesting variable syntax to automatically set the font color to either DownFF, WaitFF or GoodFF variables.
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Website status checking

Post by balala »

Yincognito wrote: September 9th, 2020, 3:35 pm Just so you know, there isn't an absolute need to use Lua to write that log (unless you have more complex things that you want to be written there). One can use the !WriteKeyValue bang to pretty much do the same, and then optionally either @Include the file in the skin so you can have all those variables at your disposal (maybe you want to do other things with them) or parse the log file itself to get its contents (obviously, the parsing can be further refined).
A major difference between writing with a lua script and writing with the !WriteKeyValue bang is that if you write using !WriteKeyValue, the file you're writing to has to be formated as a .ini file, with sections and Variable=Value options. With lua you don't have this limitation.
User avatar
Yincognito
Posts: 2934
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Website status checking

Post by Yincognito »

balala wrote: September 9th, 2020, 4:18 pm A major difference between writing with a lua script and writing with the !WriteKeyValue bang is that if you write using !WriteKeyValue, the file you're writing to has to be formated as a .ini file, with sections and Variable=Value options. With lua you don't have this limitation.
That's true. However, unless one wants that file's format to be of some other specific type, this limitation isn't so bad, as it can avoid the need to parse the file yourself to look for a specific line or place where to overwrite the data, for example. You can even number the lines this way.

Of course, this all depends on whether another format is absolutely needed for the file, but IMHO since we talk about Rainmeter, having the file written in the INI format doesn't pose significant drawbacks. If they are, they can easily be circumvented by displaying or using just the values of the options in the skin instead of the raw text. Also, nothing forces the user to have more than one [Section] or Key= strings per file, and then be able to write "free flowing" text after it.

In the end, I guess it boils down to what requirements exist for one scenario or another. :confused:
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Website status checking

Post by balala »

Yincognito wrote: September 9th, 2020, 5:21 pm In the end, I guess it boils down to what requirements exist for one scenario or another. :confused:
Exactly! :thumbup:
User avatar
jsmorley
Developer
Posts: 21489
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Website status checking

Post by jsmorley »

One thing I would keep in mind with using !WriteKeyValue instead of writing a file with Lua is that each and every call to !WriteKeyValue will open, write and close the file. I would be very hesitant to do that for more than a handful of lines at a time, as the hard drive thrashing would not please me particularly. Not saying that is an issue in this case, I confess I have not really followed this. I'm just saying that !WriteKeyValue is pretty "brute force", and I'd be hesitant to see it as an alternative to properly opening a file once, writing to it once or a thousand times, and then closing it.
User avatar
Yincognito
Posts: 2934
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Website status checking

Post by Yincognito »

jsmorley wrote: September 9th, 2020, 7:26 pm One thing I would keep in mind with using !WriteKeyValue instead of writing a file with Lua is that each and every call to !WriteKeyValue will open, write and close the file. I would be very hesitant to do that for more than a handful of lines at a time, as the hard drive thrashing would not please me particularly. Not saying that is an issue in this case, I confess I have not really followed this. I'm just saying that !WriteKeyValue is pretty "brute force", and I'd be hesitant to see it as an alternative to properly opening a file once, writing to it once or a thousand times, and then closing it.
Actually I wanted to ask this question about !WriteKeyValue for a quite a while. So !WriteKeyValue does this every time - too bad ... but does this happen when you have multiple !WriteKeyValue bangs in the same option, say, one after another? Isn't there a way to "aggregate" these writes in one open/close file cycle when it's obvious that the writes happen in strict succession? :???:

EDIT: I think doing [!WriteKeyValue Section "Key0" "Value0#CRLF#Key1=Value1#CRLF#Key2=Value2#CRLF#..." "SomePathSomeFile"] would do the trick, writing the whole thing in just one open/close file cycle. Sure, for convenience, these Key=Value parts would have to be aggregated in a String measure beforehand, but it does work. It could even be more comfortable to do it like that when needed, as it would greatly reduce the length of the option in which the "normal" successive !WriteKeyValue bangs would have been placed...

EDIT2: The drawback in doing the above is that, assuming Key1, Key2 and such already exist in the file, Rainmeter wouldn't search for Key1, Key2, etc. in order to place the options and values where they already are by overwriting the existing identical options. So, this approach would work flawlessly only if these Keys are consecutively placed in the file, one after the other.
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Website status checking

Post by balala »

Yincognito wrote: September 9th, 2020, 7:47 pm Actually I wanted to ask this question about !WriteKeyValue for a quite a while. So !WriteKeyValue does this every time - too bad ... but does this happen when you have multiple !WriteKeyValue bangs in the same option, say, one after another? Isn't there a way to "aggregate" these writes in one open/close file cycle when it's obvious that the writes happen in strict succession? :???:

EDIT: I think doing [!WriteKeyValue Section "Key0" "Value0#CRLF#Key1=Value1#CRLF#Key2=Value2#CRLF#..." "SomePathSomeFile"] would do the trick, writing the whole thing in just one open/close file cycle. Sure, for convenience, these Key=Value parts would have to be aggregated in a String measure beforehand, but it does work. It could even be more comfortable to do it like that when needed, as it would greatly reduce the length of the option in which the "normal" successive !WriteKeyValue bangs would have been placed...

EDIT2: The drawback in doing the above is that, assuming Key1, Key2 and such already exist in the file, Rainmeter wouldn't search for Key1, Key2, etc. in order to place the options and values where they already are by overwriting the existing identical options. So, this approach would work flawlessly only if these Keys are consecutively placed in the file, one after the other.
Actually this technique works ONLY if the keys starting from Key1 don't already exist. If the exist, they are not overwritten, only the first one is. But if the keys are not there, then this procedure looks to be quite efficient (unless if I'm not missing something).
User avatar
Yincognito
Posts: 2934
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Website status checking

Post by Yincognito »

balala wrote: September 9th, 2020, 8:27 pm Actually this technique works ONLY if the keys starting from Key1 don't already exist. If the exist, they are not overwritten, only the first one is. But if the keys are not there, then this procedure looks to be quite efficient (unless if I'm not missing something).
Yes, you're right. The former happens because the key being written is Key0 and because the new line characters separate options in Rainmeter / Rainmeter INI format. Yep, it has its pros and cons, indeed.
User avatar
balala
Rainmeter Sage
Posts: 11857
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Website status checking

Post by balala »

Yincognito wrote: September 9th, 2020, 8:44 pm Yep, it has its pros and cons, indeed.
As otherwise almost everything.