It is currently March 29th, 2024, 3:20 pm

Using output of a Webparser in another Webparser

Get help with creating, editing & fixing problems with skins
zdzihu
Posts: 9
Joined: October 10th, 2014, 7:44 am

Using output of a Webparser in another Webparser

Post by zdzihu »

Hello. I'm working on a skin which will display current weather conditions. I want the user to input the physical location (as in name of the city) in order to display info like temperature, humidity, weather description, etc.

So far I've managed to get the weather code based on the location input using Webparser:

Code: Select all

[mCodeParser]
Measure=WebParser
URL=https://weather.codes/search/?q=#location_goes_here#
RegExp=(?siU)<dt>(.*)</dt>

[mCodeOutput]
Measure=WebParser
Url=[mCodeParser]
StringIndex=1
Now I'd like to take code I got (the output of [mCodeOutput] and put it into next parser, which will get me the actual weather info:

Code: Select all

[mWeatherParser]
Measure=WebParser
URL=https://weather.com/weather/today/l/#code_goes_here#
RegExp=... (all the stuff I want)

[mWeatherOutput]
Measure=Webparser
URL=[mWeatherParser]
StringIndex=1

...
But I can't get the [mCodeOutput] string to be applied to the URL of [mWeatherParser]. How can I get it done properly?
This is the single least-secure password manager I have ever seen... ;-)
http://rainmeter.net/forum/viewtopic.php?f=5&t=20424&p=109151#p109151
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: Using output of a Webparser in another Webparser

Post by FreeRaider »

Have a look at URL

Code: Select all

[mWeatherParser]
Measure=WebParser
URL=https://weather.com/weather/today/l/[&mCodeOutput]
RegExp=... (all the stuff I want)
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Using output of a Webparser in another Webparser

Post by kyriakos876 »

If I understand correctly, I had the same question some time ago. Check what solved it here:
https://forum.rainmeter.net/viewtopic.php?f=5&t=29822&p=154175&hilit=webparser#p154175
zdzihu
Posts: 9
Joined: October 10th, 2014, 7:44 am

Re: Using output of a Webparser in another Webparser

Post by zdzihu »

Thanks for the replies. I did read the URL section of the Webparser measure, but for some reason casting the [mCodeOutput] measure as a section variable doesn't work for me. Neither did the whole parent-child solution, but I guess that's cause I'm simply too much of an idiot to understand it properly.

Fortunately, while I didn't manage to solve it in a proper way, I got it working via silly workaround. I noticed how I could use variables in links and decided to push the code into a variable first, then use it in the [mWeather] parser to get the info I wanted. I also learned I can skip the child measure to get the bits of data, so I moved that into the parent parser for location code (since I'm looking for just 1 piece of data).

Code: Select all

; variable to store the actual location
vLocation = Szczebrzeszyn

; variable to store the code
cCode = lets_pretend_im_a_null

[mCode]
Measure=WebParser
URL=https://weather.codes/search/?q=#vLocation#
RegExp=(?siU)<dt>(.*)</dt>
StringIndex=1
OnChangeAction=[!SetVariable cCode [mCode]][!UnpauseMeasure mWeather]

[mWeather]
Measure=WebParser
URL=https://weather.com/weather/today/l/#cCode#
RegExp=(?siU)<div class="today_nowcard-temp"><span class="">(.*)<sup>°<\/sup><\/span><\/div><div class="today_nowcard-phrase">(.*)<\/div>
DynamicVariables=1
Paused=1
Yeah I know it's stupid, but hey... As long as it works...
This is the single least-secure password manager I have ever seen... ;-)
http://rainmeter.net/forum/viewtopic.php?f=5&t=20424&p=109151#p109151
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using output of a Webparser in another Webparser

Post by balala »

FreeRaider wrote: January 13th, 2019, 8:26 pm Have a look at URL

Code: Select all

[mWeatherParser]
Measure=WebParser
URL=https://weather.com/weather/today/l/[&mCodeOutput]
RegExp=... (all the stuff I want)
Also note here that the above [mWeatherParser] WebParser measure requires a DynamicVariables=1 option. It's very important, don't forget to add it, otherwise the measure won't work:

Code: Select all

[mWeatherParser]
Measure=WebParser
URL=https://weather.com/weather/today/l/[&mCodeOutput]
RegExp=... (all the stuff I want)
DynamicVariables=1
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Using output of a Webparser in another Webparser

Post by kyriakos876 »

Instead of pause and unpause try disable and enable on the measure. And instead of OnChangeAction try FinishAction see if that works.
I think the paused tries to parse the thing regardless and there's nothing to parse so it will try again on the default update time. Instead, the disable won't allow it to parse at all until there's something fetched by the "parent".
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using output of a Webparser in another Webparser

Post by balala »

kyriakos876 wrote: January 14th, 2019, 7:55 pm Instead of pause and unpause try disable and enable on the measure. And instead of OnChangeAction try FinishAction see if that works.
I think the paused tries to parse the thing regardless and there's nothing to parse so it will try again on the default update time. Instead, the disable won't allow it to parse at all until there's something fetched by the "parent".
Not exactly. Take care the followings: https://forum.rainmeter.net/viewtopic.php?f=5&t=30748&p=156963&hilit=disable+webparser#p156967
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Using output of a Webparser in another Webparser

Post by kyriakos876 »

balala wrote: January 14th, 2019, 8:06 pm Not exactly. Take care the followings: https://forum.rainmeter.net/viewtopic.php?f=5&t=30748&p=156963&hilit=disable+webparser#p156967
I'm not sure if that's counter to what I said. I said that it might be possible for the "default update rate" to affect the "child". The child will indeed see the value of the parent no matter what and everything will be able to see the child's setting, but if the first time the parent tries to fetch information and has troubles, the child will retrieve nothing, and then it will wait for the next update (default update rate) eventhought the parent will have already fetched the information just a bit too little for the child.
I might be wrong as I'm not too familiar with WebParser, but that sounds like the logical thing to happen, to me at least.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Using output of a Webparser in another Webparser

Post by balala »

kyriakos876 wrote: January 15th, 2019, 6:53 pm I'm not sure if that's counter to what I said. I said that it might be possible for the "default update rate" to affect the "child". The child will indeed see the value of the parent no matter what and everything will be able to see the child's setting, but if the first time the parent tries to fetch information and has troubles, the child will retrieve nothing, and then it will wait for the next update (default update rate) eventhought the parent will have already fetched the information just a bit too little for the child.
I might be wrong as I'm not too familiar with WebParser, but that sounds like the logical thing to happen, to me at least.
Yep, you're right, I just added that doesn't matter if child WebParser measures are enabled / unpaused or disabled / paused, they anyway will return the appropriate information, when the parent (based on its UpdateRate) parses the information.
Otherwise, yes, you're right.