It is currently April 27th, 2024, 12:00 am

Using webparser string on another webparser

Get help with creating, editing & fixing problems with skins
grodcor
Posts: 5
Joined: May 14th, 2020, 7:39 am

Using webparser string on another webparser

Post by grodcor »

Hello,

I'm trying to create a skin that calculates if there's a heatwave situation based on normal temperatures and actual temperatures.

the thing is I'm using two different API to retrieve the data.

The first returns actual temperature and the longitude and latitude coordenates. I need these two to call the next API

Something like "URL=http://www.xxxxxx.xxx/lat=#latitude#,lon=#longitude#"

This is my approximation:

Code: Select all

[Variables]
lon=0
lat=0

[GetWeather]
	Measure=WebParser
	URL=http://api.openweathermap.org/data/2.5/weather?id=3110044&units=metric&mode=xml&appid=aaf61c6d02e79b07215a7f91adcb3e76
	RegExp=(?siU)lon="(.*)".*lat="(.*)">

[Longitud]
	Measure=WebParser
	URL=[GetWeather]
	StringIndex=1
	IfCondition=[longitud]<>#lon#
	IfTrueAction=!SetVariable "lon" "[longitud]"
	DynamicVariables=1

[Latitud]
	Measure=WebParser
	URL=[GetWeather]
	StringIndex=2
	IfCondition=[latitud]<>#lat#
	IfTrueAction=!SetVariable "lat" "[latitud]"
	DynamicVariables=1

[GetNormal]
	Measure=WebParser
	Url=https://api.openweathermap.org/data/2.5/onecall?lat=#lat#&lon=#lon#&exclude=hourly,minutely&units=metric&appid=aaf61c6d02e79b07215a7f91adcb3e76
	RegExp=(?siU)"min":(.*),"max":(.*),
	DynamicVariables=1
	
[Min]
	Measure=WebParser
	URL=[GetNormal]
	StringIndex=1

[Max]
	Measure=WebParser
	URL=[GetNormal]
	StringIndex=2
[text2]
	Meter=string
	fontsize=50
	Measurename=longitud
	Measurename2=latitud
	text=%1:%2 - #lon#:#lat#
	DynamicVariables=1
But it dowsn't work... It update the variable... but dont update the second webparser, resulting in a call for lat=0 and Lon=0

How can I refresh the second webparser after updating the variables?

Thx!!
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Using webparser string on another webparser

Post by mak_kawa »

Hi grodcor

FinishAction= for the WebParser measure specifies action(s) when the measure operation is finished. So, to update the second WebParser measure when the first is finished, you can do as follows;

Code: Select all

[GetWeather]
Measure=WebParser
URL=http://api.openweathermap.org/data/2.5/weather?id=3110044&units=metric&mode=xml&appid=aaf61c6d02e79b07215a7f91adcb3e76
RegExp=(?siU)lon="(.*)".*lat="(.*)">
FinishAction=[!CommandMeasure GetNormal Update]
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Using webparser string on another webparser

Post by jsmorley »

Right. I would take one other step:

Code: Select all

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

[Variables]
lon=0
lat=0

[GetWeather]
	Measure=WebParser
	URL=http://api.openweathermap.org/data/2.5/weather?id=3110044&units=metric&mode=xml&appid=aaf61c6d02e79b07215a7f91adcb3e76
	RegExp=(?siU)lon="(.*)".*lat="(.*)">
	FinishAction=[!EnableMeasureGroup LatLong][!CommandMeasure GetNormal "Update"]
	
[Longitud]
	Measure=WebParser
	URL=[GetWeather]
	Group=LatLong
	Disabled=1
	StringIndex=1
	IfCondition=[longitud]<>#lon#
	IfTrueAction=!SetVariable "lon" "[longitud]"
	DynamicVariables=1

[Latitud]
	Measure=WebParser
	URL=[GetWeather]
	Group=LatLong
	Disabled=1
	StringIndex=2
	IfCondition=[latitud]<>#lat#
	IfTrueAction=!SetVariable "lat" "[latitud]"
	DynamicVariables=1

[GetNormal]
	Measure=WebParser
	Url=https://api.openweathermap.org/data/2.5/onecall?lat=#lat#&lon=#lon#&exclude=hourly,minutely&units=metric&appid=aaf61c6d02e79b07215a7f91adcb3e76
	RegExp=(?siU)"min":(.*),"max":(.*),
	DynamicVariables=1
	
[Min]
	Measure=WebParser
	URL=[GetNormal]
	StringIndex=1

[Max]
	Measure=WebParser
	URL=[GetNormal]
	StringIndex=2
[text2]
	Meter=string
	fontsize=50
	Measurename=longitud
	Measurename2=latitud
	text=%1:%2 - #lon#:#lat#
	DynamicVariables=1
So I Disable the [Latitud] and [Longitud] measures until the parent measure is finished, so they are not trying to self-reference a value that won't exist on the first update of the skin. This is mostly just to eliminate one transitory error message in the log from the IfCondition.
grodcor
Posts: 5
Joined: May 14th, 2020, 7:39 am

Re: Using webparser string on another webparser

Post by grodcor »

Wow, thx!

It worked

One question: You can't use FINISHACTION to update the variables instead of that ifcondition?
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using webparser string on another webparser

Post by balala »

grodcor wrote: May 31st, 2020, 1:17 pm One question: You can't use FINISHACTION to update the variables instead of that ifcondition?
But yes, you can, however this is not needed. In fact the lat and lon variables are not needed at all. The code can work even without them:

Code: Select all

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

[Variables]
;lon=0
;lat=0

[GetWeather]
Measure=WebParser
URL=http://api.openweathermap.org/data/2.5/weather?id=3110044&units=metric&mode=xml&appid=aaf61c6d02e79b07215a7f91adcb3e76
RegExp=(?siU)lon="(.*)".*lat="(.*)">
FinishAction=[!EnableMeasureGroup LatLong][!CommandMeasure GetNormal "Update"]

[Longitud]
Measure=WebParser
URL=[GetWeather]
Group=LatLong
Disabled=1
StringIndex=1
;IfCondition=[longitud]<>#lon#
;IfTrueAction=!SetVariable "lon" "[longitud]"
DynamicVariables=1

[Latitud]
Measure=WebParser
URL=[GetWeather]
Group=LatLong
Disabled=1
StringIndex=2
;IfCondition=[latitud]<>#lat#
;IfTrueAction=!SetVariable "lat" "[latitud]"
DynamicVariables=1

[GetNormal]
Measure=WebParser
Url=https://api.openweathermap.org/data/2.5/onecall?lat=[&Latitud]&lon=[&Longitud]&exclude=hourly,minutely&units=metric&appid=aaf61c6d02e79b07215a7f91adcb3e76
RegExp=(?siU)"min":(.*),"max":(.*),
DynamicVariables=1
Disabled=1
Group=LatLong

[Min]
Measure=WebParser
URL=[GetNormal]
StringIndex=1

[Max]
Measure=WebParser
URL=[GetNormal]
StringIndex=2

[text2]
Meter=string
fontsize=50
Measurename=longitud
Measurename2=latitud
MeasureName3=Min
MeasureName4=Max
text=%1:%2 - %3 : %4
DynamicVariables=1
Note that I added the MeasureName3 and measureName4 options to the [text2] meter and modified the Text option of the same meter. I also completely removed the lan and lon variables, as they are not needed anymore in this code.
grodcor
Posts: 5
Joined: May 14th, 2020, 7:39 am

Re: Using webparser string on another webparser

Post by grodcor »

Thx, that's a much better solution.

EDIT: ok, last question, master:

Now, I'm trying to calculate the average temperature ((min+max)/2) and always receive a 0 value:

Code: Select all

[average]
Measure=Calc
Formula=(([Min]+[Max])/2)

[text2]
Meter=string
fontsize=50
Measurename=longitud
Measurename2=latitud
MeasureName3=Min
MeasureName4=Max
Measurename5=average
text=%1:%2 - %3 : %4 - %5
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using webparser string on another webparser

Post by balala »

grodcor wrote: June 1st, 2020, 3:03 pm Thx, that's a much better solution.
Not necessarily, it's just another solution of the same problem. Not better, not worst, just another.
grodcor wrote: June 1st, 2020, 3:03 pm Now, I'm trying to calculate the average temperature ((min+max)/2) and always receive a 0 value:
Add a DynamicVariables=1 option to the [average] measure. This option is needed, because the measure uses two section variables ([Min] and [Max]), which are requiring setting on the dynamic variables.