It is currently April 28th, 2024, 7:27 am

Time Bounding Skin Refresh from Interwebby

Get help with creating, editing & fixing problems with skins
PhantomRAM
Posts: 11
Joined: November 13th, 2016, 7:33 pm

Time Bounding Skin Refresh from Interwebby

Post by PhantomRAM »

Given: Skin that pulls data from internet site every 15 min. Data pulled is static nights and weekends.

Question: Is there a method or code example where I can timebound the refresh to ONLY occur M-F 9am - 5pm?

Appreciate any tips/examples.
User avatar
balala
Rainmeter Sage
Posts: 16183
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Time Bounding Skin Refresh from Interwebby

Post by balala »

PhantomRAM wrote: November 23rd, 2023, 7:00 pm Data pulled is static nights and weekends.
What do you mean by this?
PhantomRAM wrote: November 23rd, 2023, 7:00 pm Question: Is there a method or code example where I can timebound the refresh to ONLY occur M-F 9am - 5pm?
There definitely is, but how can be done depends on what exactly the measure is returning, how those expressions are looking. For instance the day of week is returned as a letter, an expression or what? Also the day of week and the time is returned as a single expression or from two different measures, one for day and the other for the time?
So an example code would be nice, to let us know exactly how the expressions are looking.
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Time Bounding Skin Refresh from Interwebby

Post by Yincognito »

balala wrote: November 23rd, 2023, 7:41 pm What do you mean by this?
He means that the data he's retrieving from the internet does not change when it's night or in the weekend. Hence the desired interval for which he wants a "refresh" (well, most likely the related WebParser measures' updates actually) to happen. Basically, he wants the WebParsers to only retrieve data during the workdays period, when the site(s) update it as well.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Time Bounding Skin Refresh from Interwebby

Post by Yincognito »

PhantomRAM wrote: November 23rd, 2023, 7:00 pm Given: Skin that pulls data from internet site every 15 min. Data pulled is static nights and weekends.

Question: Is there a method or code example where I can timebound the refresh to ONLY occur M-F 9am - 5pm?

Appreciate any tips/examples.
An idea would be to use two Time measures to check out the current hour and the current weekday, then use some IfConditions in each of those measures where you enable your internet data grabbing measures - WebParser ones, I suspect - if the hour or weekday correspond to workdays' period, and disable them if not (by the way, IfConditions only work with numbers, so you should get the current weekday as a number, not string):
https://docs.rainmeter.net/manual/measures/time/
https://docs.rainmeter.net/manual/measures/general-options/ifconditions/
https://docs.rainmeter.net/manual/bangs/#EnableDisableToggleMeasure
Depending on whether you need stuff to happen immediately, updating (or commanding to update) those data grabbing measures, updating the meters and redrawing the skin via bangs like !UpdateMeasure (!CommandMeasure "Update"), !UpdateMeter and !Redraw (see the last link above) might be needed. If you're happy with letting the specific Update / UpdateDivider / UpdateRate values in your skin and measures handle that, then the last part is not needed.

As for an example, something along these lines should do:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[Hour]
Measure=Time
Format=%H

[Weekday]
Measure=Time
Format=%w

[Toggle]
Measure=Calc
IfCondition=(Hour>8)&&(Hour<17)&&(Weekday<6)
IfTrueAction=[!EnableMeasure WebParser][!UpdateMeasure WebParser][!CommandMeasure WebParser "Update"]
IfFalseAction=[!DisableMeasure WebParser][!UpdateMeasure WebParser]

[WebParser]
Measure=WebParser
URL=https://google.com
RegExp=(?siU)^(.{30}).*$
StringIndex=1
UpdateRate=600
FinishAction=[!Log "Data Retrieved"]

---Meters---

[WebParserValue]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=WebParser
Text="WebParser Value:#CRLF##CRLF#%1"
I used an additional measure (i.e. [Toggle]) simply to test both the hour and the weekday in the same place, as it's more suited here. Since the UpdateRate in [WebParser] is 600 (which corresponds to Update * UpdateDivider * UpdateRate = 1000 * 600 = 600000 ms = 600 s = 10 m) in this case, to avoid polling the site too often and get banned, updating / commanding to update is necessary to react immediately (i.e. without waiting for up to 10 minutes) and retrieve data when it's just past 9AM during workdays. A log message is printed in the Log Tab when data is retrieved for conveniency, and the enabled or disabled state of [WebParser] is visible in the Skins Tab for easy awareness of whether the measure is "on" or "off". Adapting the method to your skin is up to you.

That being said, it's possible that you might not even need the above, since, according to the default values of options in a WebParser measure, such a measure "reads the resource only if it has been modified since last read" ... so if your data is (entirely, as in the whole webpage) static, then the cache would be used instead of acessing the resource again. Unless, of course, that refers only to downloading from the said webpage, cause the manual is not entirely clear in that regard.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth