It is currently May 3rd, 2024, 10:05 pm

RegEx/Dynamic URL: Month and Year replacement

Get help with creating, editing & fixing problems with skins
adamas
Posts: 24
Joined: February 23rd, 2012, 10:51 am

RegEx/Dynamic URL: Month and Year replacement

Post by adamas »

Hey there, guys!

I'm trying to create a simple Skin that would get a picture from an URL, crop it the way I want and display it. I more or less figured out the cropping thing, but having some trouble with the URL part.
Basically I need to make an URL dynamic (smth like RegEx).
Here's the original URL for this month: http://www.wofs.com/images/custom_almanac/almanac_0312.jpg
Here's an URL for next month: http://www.wofs.com/images/custom_almanac/almanac_0412.jpg
Etc.

So basically the two variables are Month and Year. So I'm wondering if there is a way to use an URL in the Skin that would look something like:

Code: Select all

http://www.wofs.com/images/custom_almanac/almanac_%m%y.jpg
Any help on the matter would be much, much appreciated!

P.S. I did try to search the forum and google for that, but didn't find anything that would be clear enough.
Rainmeter v3.2.0 beta r2373 64-bit
Windows 8.1 with Update 3, x64
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: RegEx/Dynamic URL: Month and Year replacement

Post by KreAch3R »

Right now Webparser doesn't support dynamic variables, but they 're coming in the next betas. If you want to do it now, you would have to produce the url and then hard - write it in the skin with !Writekeyvalue, and then refresh the skin, without ending in a infinite loop (look here). I suggest waiting for the dynamic variables support.
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
adamas
Posts: 24
Joined: February 23rd, 2012, 10:51 am

Re: RegEx/Dynamic URL: Month and Year replacement

Post by adamas »

KreAch3R wrote:Right now Webparser doesn't support dynamic variables, but they 're coming in the next betas. If you want to do it now, you would have to produce the url and then hard - write it in the skin with !Writekeyvalue, and then refresh the skin, without ending in a infinite loop (look here). I suggest waiting for the dynamic variables support.
Thanks so much for your kind reply! :)
I did stumble upon this particular post that you refer to, but didn't quite figure out how to apply it to my case (=working with an image from URL; how adapt my url so variable was changed/used properly, etc.). Well, I guess the only option left is to wait for dynamic variables support then. I'm using the latest beta now (see sig.) and always keep track of new ones coming out, so I hope the dynamic variables thing will be introduced soon enough.

Thanks so much again for your answer!
Rainmeter v3.2.0 beta r2373 64-bit
Windows 8.1 with Update 3, x64
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: RegEx/Dynamic URL: Month and Year replacement

Post by Mordasius »

This should work without Dynamic Variables:

Code: Select all

[Rainmeter]
DynamicWindowSize=1

[Variables]
MonthYear=0112

[mMonYear]
Measure=Time
Format="%m%y"

[cCheckDate]
Measure=Calc
Formula=(#MonthYear#-mMonYear)
IfBelowValue=0
IfBelowAction=!Execute [!WriteKeyValue Variables "MonthYear" "[mMonYear]"] [!Refresh]

[mGetPicture]
Measure=Plugin
Plugin=WebParser
Url=http://www.wofs.com/images/custom_almanac/almanac_#MonthYear#.jpg
Download=1
UpdateRate=1800

[ShowMonthImage]
Meter=Image
MeasureName=mGetPicture
I say "should" because it was working then it stopped like the site didn't want to respond to the WebParser Plugin anymore.. :???:
Even if you put Url=http://www.wofs.com/images/custom_almanac/almanac_0212.jpg into [mGetPicture] you get nothing, but if you plug http://www.wofs.com/images/custom_almanac/almanac_0212.jpg into your browser you'll get the picture you're looking for. Most confusing.....
adamas
Posts: 24
Joined: February 23rd, 2012, 10:51 am

Re: RegEx/Dynamic URL: Month and Year replacement

Post by adamas »

Mordasius wrote:This should work without Dynamic Variables: I say "should" because it was working then it stopped like the site didn't want to respond to the WebParser Plugin anymore.. :???:
Even if you put Url=http://www.wofs.com/images/custom_almanac/almanac_0212.jpg into [mGetPicture] you get nothing, but if you plug http://www.wofs.com/images/custom_almanac/almanac_0212.jpg into your browser you'll get the picture you're looking for. Most confusing.....
Thank you SO, SO much!!! It works flawlessly! I mean, really, thanks a million, I do appreciate you taking your time to write up/adopt this. I am very much grateful! : )))


I tried forwarding a clock a month forward (4 different months) and it worked (image for March got displayed, then April, etc.), BUT when I tried forwarding it back to today the same image stayed no matter how many times I tried refreshing it. I assume this is due to "Download=1" under [mGetPicture]? Tried changing it to "Download=0" and then it did not work at all :lol: Well, in any case, it works properly on month change and it's all that matters! :)


Other than this great script I added this under [ShowMonthImage]:

Code: Select all

W=350
H=365
PreserveAspectRatio=1
ImageCrop=50,100,150,756
...to make it smaller for my 12.1" screen.


And now it's absolutely perfect! Thank you so much again! :D
Rainmeter v3.2.0 beta r2373 64-bit
Windows 8.1 with Update 3, x64
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegEx/Dynamic URL: Month and Year replacement

Post by jsmorley »

say "should" because it was working then it stopped like the site didn't want to respond to the WebParser Plugin anymore..
You might want to restart Rainmeter. It is possible that WebParser got hung up when you were rapidly testing, as it can do that sometimes if you fire WebParser again before it has time to completely finish the previous call to it.

The skin you posted works fine for me.
adamas
Posts: 24
Joined: February 23rd, 2012, 10:51 am

Re: RegEx/Dynamic URL: Month and Year replacement

Post by adamas »

Mordasius wrote:This should work without Dynamic Variables:
Now I noticed a strange thing happening. I load the skin, after around 30 secs (I assume it loads the pic off the net), it hags there fine for some time and then dissapears and never appears again. I mean, it's gone and there's no error message, no indication of why it might happen, nothing. If I do "Refresh All", it appears again and the same thing happens all over again.

Maybe it's due to this:

Code: Select all

[mGetPicture]
UpdateRate=1800
What's strange is that that there is a "Download=1" option, so I assume that image IS downloaded and stored locally and unless the image is changed it shows the locally-stored one, which is fine and all. But what happens if it CAN'T check for url change (eg. not internet)? From my point of view in this case it should STILL display locally stored version rather than nothing (due to the fact it can't check for change).

So the weird thing is that it WORKS, but then stops. I'm puzzled...


Any ideas, guys? :)
Rainmeter v3.2.0 beta r2373 64-bit
Windows 8.1 with Update 3, x64
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: RegEx/Dynamic URL: Month and Year replacement

Post by Mordasius »

jsmorley wrote:You might want to restart Rainmeter.
That certainly solved the problems I was having with just closing the skin and loading it again while testing... tnx JSM
adamas wrote:I tried forwarding a clock a month forward (4 different months) and it worked (image for March got displayed, then April, etc.), BUT when I tried forwarding it back to today the same image stayed no matter how many times I tried refreshing it. I assume this is due to "Download=1" under [mGetPicture]?
[cCheckDate] only works if you are going ahead from month to month (e.g. 0112, 0212, 0312, etc.) it won't work if you go back in time because the Variable #MonthYear# has already been overwritten by a #MonthYear# value greater than the one you are trying to go back to. This is not a problem unless you want to go back in time and I'm sorry to say that Rainmeter really can not help with any aspirations you may have for time travel.
adamas wrote:Now I noticed a strange thing happening. I load the skin, after around 30 secs (I assume it loads the pic off the net), it hags there fine for some time and then dissapears and never appears again. I mean, it's gone ...So the weird thing is that it WORKS, but then stops. I'm puzzled...
This sounds a bit like the problem I was having prior to jsmorley's advice to restart Rainmeter. What happens when you try restarting Rainmeter?
adamas
Posts: 24
Joined: February 23rd, 2012, 10:51 am

Re: RegEx/Dynamic URL: Month and Year replacement

Post by adamas »

Mordasius wrote:This sounds a bit like the problem I was having prior to jsmorley's advice to restart Rainmeter. What happens when you try restarting Rainmeter?
I did saw your comment and answer to it about restarting and I did restart my Rainmeter a whole bunch of times, but it doesn't help: every single time after 3-5 minutes it disappears and never comes back. So what works is either do a Refresh All or a program restart, but again in both cases it starts the disappearing cycle again.
The strange thing is that the code I'm using is EXACTLY the way you provided it (no changes). The only difference, as I mentioned, is this code in the [ShowMonthImage] section:

Code: Select all

W=350
H=365
PreserveAspectRatio=1
ImageCrop=50,100,150,756
And the way I see it no way in hell those 4 lines could affect anything at all. This is super-weird... I mean, I got latest beta of 2.3 Rainmeter, latest Windows with SP1 (don't think it matters much, but still), and I'm using the code just the way it was provided. And on top of that my Rainlendar uses only 1 skin (called Cowon Clock) other than the one we're discussing, and that's it. I'm puzzled...

Well, I'll try to reinstall Rainlendar from a scratch, but I don't think it'll make any difference. And will try to recreate the skin from a scratch as well.

ANY IDEAS ARE STILL VERY MUCH WELCOME! :)


Thanks so, so much again for all your kind help!! :thumbup:


EDIT: I just timed this thing, and it seems that it disappears at/around 30 minute mark. Second time >8 minutes, then gone. Third time 42 minutes and still going. So it works fine for 30 / 8 / 42+ (probably end soon too) minutes, then disappears. Good people, did anyone actually tried leaving it there for a little bit? Because if you simply add this Skin it seems to be working at first sight of course. I really don't understand what's happening here :???:
Rainmeter v3.2.0 beta r2373 64-bit
Windows 8.1 with Update 3, x64
User avatar
Mordasius
Posts: 1173
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: RegEx/Dynamic URL: Month and Year replacement

Post by Mordasius »

adamas wrote:. I really don't understand what's happening here....
Nor do I... I thought it may have been the UpdateRate=1800 in [mGetPicture] causing the problem because it seemed to be working fine with that line deleted. However, I've now put it back again and it seems to working without any problems. I'll leave it ticking over a little longer to see how long it lasts for.

UPDATE: It has now been stable for more than an hour with a modified version of [mGetPicture]

Code: Select all

[mGetPicture]
Measure=Plugin
Plugin=WebParser
Url=http://www.wofs.com/images/custom_almanac/almanac_#MonthYear#.jpg
Download=1
FinishAction= !DisableMeasure mGetPicture
I replaced UpdateRate=1800 with a FinishAction to disable [mGetPicture] completely as soon as it has got the image. This won't be a problem as the image you want only changes once a month and it could be that http://www.wofs.com doesn't like being hit on every five minutes (default) or even every half hour (UpdateRate=1800).

If this still doesn't work, you could always download all the Almanac images for 2012 manually (almanac_0112.jpg, almanac_0212.jpg, etc.) and then craft a little skin that would let you flip through the images month by month to see when to sign big contracts or plan a party without having to go back to the website.
:)