It is currently April 24th, 2024, 4:39 am

Substitute StringIndex of a WebParser

Get help with creating, editing & fixing problems with skins
PaladínOscuro
Posts: 2
Joined: March 23rd, 2018, 5:10 am

Substitute StringIndex of a WebParser

Post by PaladínOscuro »

Hello everyone. I have been trying to create my own weather skin, but I need a substitute rule I am not sure how to address or where to put it since it is not working in either the Weather measure or the string meter.

Code: Select all

[Tiempo]
Measure=WebParser
URL=[PaginaWeb]
StringIndex=3
;This is the temperature I need, comes in the format "17°C", I need only the number 17...

;The substitute I need to use, but unsure where to put it...
RegExpSubstitute=1
Substitute="^(\d{2})(.*)":"\1"

[Cadena]
Meter=String
MeasureName=?
AntiAlias=1

Thanks so much for all your help in advance.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Substitute StringIndex of a WebParser

Post by ikarus1969 »

Substitute always belongs to a measure, never to a meter (docu)
Your substitution is correct, but only for positive, 2-digit temperatures (from 10 to 99 degrees :-); the \d{2} means "exactly 2 digits").
if you want negative temperatures as well, which would come, let's say, with an optional minus-sign, the regex should be:

Code: Select all

Substitute="^(-?\d+).*":"\1"
But this still don't handle fractional values...
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Substitute StringIndex of a WebParser

Post by FreeRaider »

Another solution for example:

Code: Select all

[MeasureString]
Measure=String
String="-15.34°C"
RegExpSubstitute=1
Substitute="(.*)\.(\d{1,}).*":"\1.\2"

[MeterString]
Meter=String
Text=[MeasureString]
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Substitute StringIndex of a WebParser

Post by jsmorley »

I wouldn't fight the decimals...

Code: Select all

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

[MeasureString]
Measure=String
String=17°C
RegExpSubstitute=1
Substitute="^(.*)°.*$":"\1"

[MeterString]
Meter=String
MeasureName=MeasureString
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Just skip everything after a ° is seen...

In my experience, temperature values in Fahrenheit seldom are returned with any decimal places, but those in Celsius sometimes are.
PaladínOscuro
Posts: 2
Joined: March 23rd, 2018, 5:10 am

Re: Substitute StringIndex of a WebParser

Post by PaladínOscuro »

Thank you so much for all your answers. I live in a tropical city so temperatures only vary between 15 and 29°C but I still appreciate all the help.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Substitute StringIndex of a WebParser

Post by pul53dr1v3r »

what would be the best way to separate content of a StringIndex such as 7 of 10?
The two numbers are necessary (as integers ofc), while the text between isn't. The text is not fixed.
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Substitute StringIndex of a WebParser

Post by balala »

Pul53dr1v3r wrote: October 17th, 2019, 5:28 pm what would be the best way to separate content of a StringIndex such as 7 of 10.
The two numbers are necessary (as integers ofc), while the text between isn't. The text is not fixed.
A regular expression substitution. For instance supposing that a following kind of measure is returning the 7 of 10 string, add the following two measures:

Code: Select all

[MeasureReturningString]
Measure=
...

[MeasureNumber1]
Measure=String
String=[MeasureReturningString]
RegExpSubstitute=1
Substitute="^(\d*) .* (\d*)$":"\1"
DynamicVariables=1

[MeasureNumber2]
Measure=String
String=[MeasureReturningString]
RegExpSubstitute=1
Substitute="^(\d*) .* (\d*)$":"\2"
DynamicVariables=1
As I hope you've figured it out, [MeasureNumber1] is returning the first number (that before of), while [MeasureNumber2] obviously is returning the other number (placed after of).
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Substitute StringIndex of a WebParser

Post by pul53dr1v3r »

balala wrote: October 17th, 2019, 5:40 pm A regular expression substitution. For instance supposing that a following kind of measure is returning the 7 of 10 string, add the following two measures:

Code: Select all

[MeasureReturningString]
Measure=
...

[MeasureNumber1]
Measure=String
String=[MeasureReturningString]
RegExpSubstitute=1
Substitute="^(\d*) .* (\d*)$":"\1"
DynamicVariables=1

[MeasureNumber2]
Measure=String
String=[MeasureReturningString]
RegExpSubstitute=1
Substitute="^(\d*) .* (\d*)$":"\2"
DynamicVariables=1
As I hope you've figured it out, [MeasureNumber1] is returning the first number (that before of), while [MeasureNumber2] obviously is returning the other number (placed after of).
I was close, but forgot to put RegExpSubstitute into the measure. :Whistle
Thanks! :great:
User avatar
balala
Rainmeter Sage
Posts: 16164
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Substitute StringIndex of a WebParser

Post by balala »

Pul53dr1v3r wrote: October 17th, 2019, 5:50 pm I was close, but forgot to put RegExpSubstitute into the measure. :Whistle
Very important! As you've seen it doesn't work if you don't set it properly. Glad if you got it working.