It is currently April 27th, 2024, 7:31 pm

Clock syncs from time.is

Get help with creating, editing & fixing problems with skins
Rube_Goldfish
Posts: 3
Joined: July 21st, 2023, 9:04 pm

Clock syncs from time.is

Post by Rube_Goldfish »

Hello,

My PC's clock is broken, so I've been using Rainmeter to make a "replacement" that covers the clock. I used to have it work with timeanddate.com, but that has since stopped working. As a replacement, I've started using time.is. Is there a way I can use a WebParser to have my clock display the time from https://time.is/New_York and update automatically? I've found a similar resource here: https://forum.rainmeter.net/viewtopic.php?t=20837

Thanks in advance!
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Clock syncs from time.is

Post by Yincognito »

Rube_Goldfish wrote: July 21st, 2023, 9:09 pm Hello,

My PC's clock is broken, so I've been using Rainmeter to make a "replacement" that covers the clock. I used to have it work with timeanddate.com, but that has since stopped working. As a replacement, I've started using time.is. Is there a way I can use a WebParser to have my clock display the time from https://time.is/New_York and update automatically? I've found a similar resource here: https://forum.rainmeter.net/viewtopic.php?t=20837

Thanks in advance!
Just to be sure, are you certain your PC's clock is so broken that you can't do what's in these pictures? If the answer is no, then feel free to fix your clock that way, and use the Rainmeter skin equivalent just because it looks better. If the answer is yes, then sure, WebParser can do that, using a code similar to this:

Code: Select all

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

---Measures---

[TimeIs]
Measure=WebParser
URL=https://time.is/New_York
RegExp=(?siU)<time id="clock">(.*)<\/time>
StringIndex=1
FinishAction=[!Log "Minute synchronization with time.is completed."]
UpdateRate=60

---Meters---

[TimeIsValue]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=TimeIs
Text=Time Is = %1
The above will retrieve the time roughly every minute (i.e. Update x UpdateDivider x UpdateRate = 1000 x 1 x 60 = 60000 milliseconds), but it can be adjusted, as long as the site permits this and doesn't ban your IP for polling it too often and such. I added a message to the log for conveniency, you can remove it if you don't need it.

In case you wonder, all this WebParser thing is just a matter of right clicking on the webpage, choose View Page Source (at least that's how it reads in Chrome) and CTRL+F to find what you're after. If you found it, it means WebParser can retrieve it. If you didn't find it, it means the data is "hidden" behind some Javascript function that provides it. The rest is building the regular expression (aka regex) to extract the desired data - as you can see, in this case it was really simple.
Last edited by Yincognito on July 25th, 2023, 11:12 am, edited 1 time in total.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16179
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Clock syncs from time.is

Post by balala »

Rube_Goldfish wrote: July 21st, 2023, 9:09 pm My PC's clock is broken,
What does this mean? A computer running any version of Windows doesn't work if it has no working clock (at least as far as I know). So I assume it can't be broken. This is why am I asking what do you mean by broken.
Rube_Goldfish
Posts: 3
Joined: July 21st, 2023, 9:04 pm

Re: Clock syncs from time.is

Post by Rube_Goldfish »

Yincognito wrote: July 21st, 2023, 10:37 pm Just to be sure, are you certain your PC's clock is so broken that you can't do what's in these pictures? If the answer is no, then feel free to fix your clock that way, and use the Rainmeter skin equivalent just because it looks better. If the answer is yes, then sure, WebParser can do that, using a code similar to this:

Code: Select all

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

---Measures---

[TimeIs]
Measure=WebParser
URL=https://time.is/New_York
RegExp=(?siU)<time id="clock">(.*)<\/time>
StringIndex=1
FinishAction=[!Log "Minute yynchronization with time.is completed."]
UpdateRate=60

---Meters---

[TimeIsValue]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=TimeIs
Text=Time Is = %1
The above will retrieve the time roughly every minute (i.e. Update x UpdateDivider x UpdateRate = 1000 x 1 x 60 = 60000 milliseconds), but it can be adjusted, as long as the site permits this and doesn't ban your IP for polling it too often and such. I added a message to the log for conveniency, you can remove it if you don't need it.

In case you wonder, all this WebParser thing is just a matter of right clicking on the webpage, choose View Page Source (at least that's how it reads in Chrome) and CTRL+F to find what you're after. If you found it, it means WebParser can retrieve it. If you didn't find it, it means the data is "hidden" behind some Javascript function that provides it. The rest is building the regular expression (aka regex) to extract the desired data - as you can see, in this case it was really simple.
This is working pretty well, but I'm wondering something. Right now, it displays -- for example -- 05:01:20<span id="ampm" style="font-size:12px;line-height:12px">PM</span>, which is too big to fit over my PC clock. Could I cut it down to just the hour and minute and AM/PM?
balala wrote: July 22nd, 2023, 6:35 am What does this mean? A computer running any version of Windows doesn't work if it has no working clock (at least as far as I know). So I assume it can't be broken. This is why am I asking what do you mean by broken.
My PC's clock tends to randomly skip around and jump back in time (be it a few minutes or closer to an hour) every hour or so, and it'll keep desyncing further if I don't manually correct it, no matter what I set the time server to. Similarly, it doesn't count time when it's shut off; I booted it up this morning and it was still on the day before, since I hadn't used it yesterday.
User avatar
balala
Rainmeter Sage
Posts: 16179
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Clock syncs from time.is

Post by balala »

Rube_Goldfish wrote: July 25th, 2023, 12:05 am My PC's clock tends to randomly skip around and jump back in time (be it a few minutes or closer to an hour) every hour or so, and it'll keep desyncing further if I don't manually correct it, no matter what I set the time server to. Similarly, it doesn't count time when it's shut off; I booted it up this morning and it was still on the day before, since I hadn't used it yesterday.
This leads me thinking to a CMOS battery failure. Even if not entirely explains what did you describe, I'd be tempted to try fixing the problem by replacing the battery. If you don't know how to do this, ask for help, but I definitely would try this. If I am right and the battery failure is causing the time problem, replacing it should fix the problem. Using a provider like timeanddate.com (or any other) to sync the clock is not a good choice.
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Clock syncs from time.is

Post by Yincognito »

Rube_Goldfish wrote: July 25th, 2023, 12:05 am This is working pretty well, but I'm wondering something. Right now, it displays -- for example -- 05:01:20<span id="ampm" style="font-size:12px;line-height:12px">PM</span>, which is too big to fit over my PC clock. Could I cut it down to just the hour and minute and AM/PM?
Apparently, you set your clock to be displayed this way on that site, or it came like that by default. For me, the above code produces only the hour:min:sec part, hence the form of the code I suggested. But anyway, yes, it can be made to do what you want. Two approaches are possible:
- do it by adjusting the WebParser measure's RegExp further
- do it by adding a regex Substitute to the WebParser measure
Normally, you'd avoid the former, in case you set the site to provide time like it does for me, so the latter is a better choice. Add something like this to the TimeIs measure:

Code: Select all

RegExpSubstitute=1
Substitute="(?siU)^.*(\d+):(\d+):(\d+)<span .*>(.*)<\/span>.*$":"\1:\2 \4"
If now you get what you described, after adding this you should get the desired outcome.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
Rube_Goldfish
Posts: 3
Joined: July 21st, 2023, 9:04 pm

Re: Clock syncs from time.is

Post by Rube_Goldfish »

Hey, just out of curiosity, I don't see this working anymore. The "Time Is = " code is just empty after this.
User avatar
balala
Rainmeter Sage
Posts: 16179
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Clock syncs from time.is

Post by balala »

Rube_Goldfish wrote: January 11th, 2024, 8:47 pm Hey, just out of curiosity, I don't see this working anymore. The "Time Is = " code is just empty after this.
Try adding the following option to the [TimeIs] measure: UserAgent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.84.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: Clock syncs from time.is

Post by SilverAzide »

Rube_Goldfish wrote: January 11th, 2024, 8:47 pm Hey, just out of curiosity, I don't see this working anymore. The "Time Is = " code is just empty after this.
That site seems to be displaying the time using javascript, so you can't scrape it anymore. That means it is time for you to find a new website.

;-) See what I did there?
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 7178
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Clock syncs from time.is

Post by Yincognito »

SilverAzide wrote: January 11th, 2024, 9:56 pm That site seems to be displaying the time using javascript, so you can't scrape it anymore. That means it is time for you to find a new website.

;-) See what I did there?
Hmm... the code here still works for me, after adding the UserAgent suggested by balala (plus, I am able to CTRL+F the time in the page source, so it doesn't look to be hidden behind javascript... yet):
TimeIs.jpg
That being said, at the time I posted the code, Rube_Goldfish above got something different than I did too, so maybe the site provides slightly different results depending on user location... :confused:
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth