It is currently March 29th, 2024, 6:33 am

WebParser pulling a number with a comma

Get help with creating, editing & fixing problems with skins
DenBla
Posts: 2
Joined: January 2nd, 2017, 2:24 am

WebParser pulling a number with a comma

Post by DenBla »

Having a bit of trouble with this one, it is my first real try at setting up a skin or using LUA.

Code: Select all

    [MeasureWins]
    Measure=Plugin
    Plugin=WebParser
    Url=#URL#
    RegExp='(?siU)<span class="wins">(.*)</span>'
    StringIndex=1

&

Code: Select all

    [MeasureLosses]
    Measure=Plugin
    Plugin=WebParser
    Url=#URL#
    RegExp='(?siU)<span class="losses">(.*)</span>'
    StringIndex=1
Using the above, pulling the value from the webiste https://www.dotabuff.com/ I get the numeric value of

Code: Select all

    1,613  
&

Code: Select all

    1,521  

Which Rainmeter reads as either 1.610 or 1 serperately from 610, ditto for MeasureLosses? Not entirely sure. But when using

Code: Select all

    [MeasureGames]
    measure=calc
    Formula=MeasureWins + MeasureLosses
Gives me a total of 2.
Thus resulting in it reading the comma as a decimal place or seperator.
My question is, is there any way to force it to ignore the comma?
I have tried in the Parser, using:

Code: Select all

    Substitute=",":""

But this produces the same results.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WebParser pulling a number with a comma

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureParent]
Measure=Plugin
Plugin=WebParser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)<span class="wins">(.*)</span>.*<span class="losses">(.*)</span>
FinishAction=[!EnableMeasure MeasureDifference]

[MeasureWins]
Measure=Plugin
Plugin=WebParser
URL=[MeasureParent]
StringIndex=1
Substitute=",":""

[MeasureLosses]
Measure=Plugin
Plugin=WebParser
URL=[MeasureParent]
StringIndex=2
Substitute=",":""

[MeasureDifference]
Measure=Calc
Formula=[MeasureWins] - [MeasureLosses]
DynamicVariables=1
Disabled=1

[MeterDifference]
Meter=String
MeasureName=MeasureDifference
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
So you DO want to use Substitute to remove the commas, but then you have to use the "string value" of the measure(s) so that you get the substituted string to use in the Calc measure.

A string like "1,234" is NOT a "number" in any programming sense. It can't be used in a Calc measure, or it will just return "1", since it will ignore anything after the comma. So we use the "string value" of the WebParser child measures, by using the [SectionVariable] form and DynamicVariables=1. That will get the substituted string value from the child, and then a Calc measure will happily turn "1234" into the real number 1234.

https://docs.rainmeter.net/manual/variables/section-variables/

P.S. Don't use 'single quotes' in Rainmeter. You don't need quotes at all around a RegExp, and where you do need quotes, only use "double quotes".
DenBla
Posts: 2
Joined: January 2nd, 2017, 2:24 am

Re: WebParser pulling a number with a comma

Post by DenBla »

jsmorley wrote:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureParent]
Measure=Plugin
Plugin=WebParser
URL=file://#CURRENTPATH#Test.html
RegExp=(?siU)<span class="wins">(.*)</span>.*<span class="losses">(.*)</span>
FinishAction=[!EnableMeasure MeasureDifference]

[MeasureWins]
Measure=Plugin
Plugin=WebParser
URL=[MeasureParent]
StringIndex=1
Substitute=",":""

[MeasureLosses]
Measure=Plugin
Plugin=WebParser
URL=[MeasureParent]
StringIndex=2
Substitute=",":""

[MeasureDifference]
Measure=Calc
Formula=[MeasureWins] - [MeasureLosses]
DynamicVariables=1
Disabled=1

[MeterDifference]
Meter=String
MeasureName=MeasureDifference
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
So you DO want to use Substitute to remove the commas, but then you have to use the "string value" of the measure(s) so that you get the substituted string to use in the Calc measure.

A string like "1,234" is NOT a "number" in any programming sense. It can't be used in a Calc measure, or it will just return "1", since it will ignore anything after the comma. So we use the "string value" of the WebParser child measures, by using the [SectionVariable] form and DynamicVariables=1. That will get the substituted string value from the child, and then a Calc measure will happily turn "1234" into the real number 1234.

https://docs.rainmeter.net/manual/variables/section-variables/

P.S. Don't use 'single quotes' in Rainmeter. You don't need quotes at all around a RegExp, and where you do need quotes, only use "double quotes".
Thank You so much for that explanation and information. I have all parts of my skin up and running now :party:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: WebParser pulling a number with a comma

Post by jsmorley »

Glad to help.