It is currently May 9th, 2024, 3:49 am

Using part of a returned string

Get help with creating, editing & fixing problems with skins
Cymril
Posts: 6
Joined: January 5th, 2012, 1:28 am

Using part of a returned string

Post by Cymril »

I'm working on my first skin, and there's probably a blindly obvious answer to this that I just can't find/missed. Googling around has found that a lua script might be able to do it, but I don't want to have to run a script for something so simple, and there's a post on here from 2 years ago by one of the developers that's sort of what I need, but I don't know if that got implemented and in what form it would have taken.

I'm trying to make a skin for LoLReplay, that'll display the last few saved replays and the first win timer. The value of the timer is stored in a registry key, which I can pull up fine, but the problem is that the registry value is a string in the form of "accountname (server) time in seconds". I was wondering if there is a way to grab just the numbers or pull it out of the returned string?

The conversion thing in the sample code on pulling values from the registry with calc won't work because the string also contains letters. And I know there's things like RegEx=, but I'm pretty sure that only works for stuff within WebParser? And I can't display the value as is, because the time is stored as the number of seconds since Jan 1st 1970, so it's not very useful without converting it (which will be the next challenge, once I can figure this one out).

Like I said, there's probobly something really simple I've just missed in all my searching, and I appreciate any help could get.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Using part of a returned string

Post by poiru »

Cymril wrote:The conversion thing in the sample code on pulling values from the registry with calc won't work because the string also contains letters. And I know there's things like RegEx=, but I'm pretty sure that only works for stuff within WebParser?
RegExpSubstitute should do the trick.
Cymril
Posts: 6
Joined: January 5th, 2012, 1:28 am

Re: Using part of a returned string

Post by Cymril »

poiru wrote: RegExpSubstitute should do the trick.
Awesome! That did indeed do the trick! I guess I brainfarted on that part, but I guess I was right about the two year old post getting implemented (and RegExp now being usable outside of WebParser).

This solves the problem for ~me~ but there are a few other people interested in the skin when it's done, and that could cause a problem (outside of the unprofessional "fix it yourself") when other people try to use the skin. I found a post, by you I believe, saying that Substitute= can't have any wildcards in it, is this still true? Because I would need to eventually have RegExp return a value without knowing the exact, explicit letters to remove from the string. But that isn't really an issue right now.

Now on to how to figure out getting Measure=Time to return values in epoch instead of human readable.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Using part of a returned string

Post by poiru »

Cymril wrote:This solves the problem for ~me~ but there are a few other people interested in the skin when it's done, and that could cause a problem (outside of the unprofessional "fix it yourself") when other people try to use the skin. I found a post, by you I believe, saying that Substitute= can't have any wildcards in it, is this still true? Because I would need to eventually have RegExp return a value without knowing the exact, explicit letters to remove from the string. But that isn't really an issue right now.

Now on to how to figure out getting Measure=Time to return values in epoch instead of human readable.
That post is probably outdated (RegExpSubstitute was added for Rainmeter 2.2 IIRC). With RegExpSubstitute=1, Substitute will allow you to match patterns similar to RegExp= in WebParser (you can use ".*" and sinilar constructs if that's what you meant by wildcards). Assuming that your string will follow some sort of pattern, you will be able to do what you want.
Cymril
Posts: 6
Joined: January 5th, 2012, 1:28 am

Re: Using part of a returned string

Post by Cymril »

Thank you again for the help!

I've managed to find a way to get the current epoch time through webparsing a site that has it stored in a webparser friendly format. As much as I'd like to keep everything local, trying to convert anything returned by Measure=Time would be a nightmarish hassle or at least require writing a lua script (which would entail learning lua), having to account for leap years and such in Rainmeter would get ugly fast; unless there's something simple I've missed.

One thing I've noticed, and I can't seem to find any information googling around, is that RegExp is always returning whatever search parameters I used, along with whatever I was actually hoping to grab, and requires a Substitute= to strip it out. I don't know if I've misconfigured something, or what?

For example,

Code: Select all

[measureGetGMT]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=-1
Url=http://www.xav.com/time.cgi
RegExp="(?siU)td align="right"><tt>(.*)</tt></td>.*"
is currently setting measureGetGMT to

Code: Select all

td align="right><tt>1325866680</tt></td>
Adding .* to the end of the search string does nothing (or, at least, that's what I assume it's supposed to do, the explanation in the webparser primer isn't very clear on the role it plays.

All RegExps do this, it was doing it when I pulled the time from the registry, but it was just odd behaviour then and not a problem because I was already substituting something from it anyway.

It's not really that big of an issue, it's just an extra line of code, but it's the fact that it's a line of code I haven't seen anyone else ~need~ that's bothering me, and makes me think I've done something wrong.

e: Also, I assume I'm correct in thinking that UpdateRate=-1 works the same as UpdateDivider=-1? In that it'll only pull down the information once when the skin loads or refreshes?


double e: can Measures run more then one calculation/return multiple variables? Basically, can I use a single measure to Subtract the current time from the time in the registry, then break up ~that~ value into hours:minutes:seconds within the same measure? Or will I need a new measure to store hours, then a new one to store minutes, etc. (essentially, if a measure references itself, does it update the value as it's running, or only when the measure is complete.
Last edited by Cymril on January 6th, 2012, 4:41 pm, edited 1 time in total.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Using part of a returned string

Post by poiru »

Cymril wrote:One thing I've noticed, and I can't seem to find any information googling around, is that RegExp is always returning whatever search parameters I used, along with whatever I was actually hoping to grab, and requires a Substitute= to strip it out. I don't know if I've misconfigured something, or what?
Add StringIndex=1 :)
Cymril wrote:e: Also, I assume I'm correct in thinking that UpdateRate=-1 works the same as UpdateDivider=-1? In that it'll only pull down the information once when the skin loads or refreshes?
Not really. Use UpdateDivider=-1 to do what you want. Here is an explanation between UpdateRate/UpdateDivider.
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using part of a returned string

Post by jsmorley »

When you are using a WebParser measure that has a RegExp= on it, and is capturing only one thing, you need to add StringIndex=1 to the measure.

Normally one would have a "parent" WebParser measure that is capturing a bunch of different elements, and then create "child" WebParser measures with URL=[ParentMeasureName] and no RegExp, then use the StringIndex to determine which of the return values from the parent measure to return in the child measure.

If you are only returning one thing in that main measure however, it is perfectly fine to just put StringIndex=1 on it, and not create any "child" measure at all.

Edit: Damn... Beat by poiru again. ;-)
Cymril
Posts: 6
Joined: January 5th, 2012, 1:28 am

Re: Using part of a returned string

Post by Cymril »

poiru wrote: Not really. Use UpdateDivider=-1 to do what you want. Here is an explanation between UpdateRate/UpdateDivider.
That makes a lot of sense, actually.

Also, thank you both!
Cymril
Posts: 6
Joined: January 5th, 2012, 1:28 am

Re: Using part of a returned string

Post by Cymril »

poiru wrote: That post is probably outdated (RegExpSubstitute was added for Rainmeter 2.2 IIRC). With RegExpSubstitute=1, Substitute will allow you to match patterns similar to RegExp= in WebParser (you can use ".*" and sinilar constructs if that's what you meant by wildcards). Assuming that your string will follow some sort of pattern, you will be able to do what you want.
This isn't happening. Substitute is simply ignoring any regular expressions and will only accept the actual characters.

I've worked around it, but it's not exactly an elegant solution;
This works:

Code: Select all

[measureGetAccount]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=SOFTWARE\LOLReplay
RegValue=firstWinTimes
RegExpSubstitutes=1
Substitute="1":"", "2":"", "3":"", "4":"", "5":"", "6":"", "7":"", "8":"", "9":"", "0":"", '{"':"", '":':"", "}":""
DynamicVariables=1
UpdateDivider=3600
This does not, but by all rights it should:

Code: Select all

[measureGetAccount]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=SOFTWARE\LOLReplay
RegValue=firstWinTimes
RegExpSubstitutes=1
Substitute="\d\d\d\d\d\d\d\d\d\d":""
DynamicVariables=1
UpdateDivider=3600
Sorry to bombard you guys with questions. Like I said, I worked around it, but I'm trying to learn how to skin, and that substitute not doing anything is confusing me.

I'm also getting three errors every time I refresh the skin, I can't see why/or find any useful information:
2 counts of Calc: #Extra operation! in measure [measureGetTime].
And 1 The meter [meterBarTimeRemaining] cannot be bound with [79200]

Relevent code sections:

Code: Select all

[measureGetTime]
Measure=Calc
Formula=(([measureGetFirstWin])-([measureGetGMT]))
DynamicVariables=1
Bracketed or not, the error persists, and I have no idea why, there are other calcs that are nearly identical and they run without problems.

and

Code: Select all

[meterBarTimeRemaining]
Meter=BAR
MeterStyle=styleBar
MeasureName=[measureTimeBar]

X=10
Y=52
W=190
H=1
(I started with illustro's 2 Disks.ini, and I like the look of it anyway)

which calls:

Code: Select all

[measureTimeBar]
;Will be used later for the meter, separate to not interfer with the counter above
Measure=Calc
Formula=[measureFWTime]
InvertMeasure=1
MaxValue=79200
MinValue=0
DynamicVariables=1
The meter is just a simple bar that will fill up in 22 hours (while FWTime counts down towards zero), but it's kicking out that error and the bar remains blank.

Again, sorry!
User avatar
Brian
Developer
Posts: 2690
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Using part of a returned string

Post by Brian »

1. You have an extra 's' at the end of your RegExpSubstitute. Should be RegExpSubstitute=1
2. The Calc errors happen because Rainmeter reads the Calc measures before [measureGetFirstWin] and [measureGetGMT] returns any values.
3. Remove the brackets in your measurename. meterBarTimeRemaining should look something like this:

Code: Select all

[meterBarTimeRemaining]
Meter=BAR
MeterStyle=styleBar
MeasureName=measureTimeBar

X=10
Y=52
W=190
H=1
-Brian