Weather Parser not working

Help with creating, editing & fixing problems with skins
User avatar

Re: Weather Parser not working

June 12th, 2018, 8:29 pm
balala
Rainmeter Sage   [6260 posts]

DanielPodo wrote:If you look at the website, I'd like to download the main icon (in the "details" box), the big temperature font and the weather description just above the temperature.

For now I succeeded to get only the temperature and the icon. Here is the RegExp I wrote: RegExp=(?siU)<span class=".*" data-reactid=".*">(\d{2})</span><span class=".*" data-reactid=".*">°</span>.*<img alt=".*" height=".*" title=".*" width=".*" class=" " src="(.*)" data-reactid=".*"/></span>.
With this RegExp, the measure using StringIndex=1 returns the temperature and the one using StringIndex=2, the icon.
Right now I have no more time to work with it, because the midnight is coming here, so I go to sleep. If you can't figure out the rest, tomorrow I'll try to finish it to get the description as well.

Re: Weather Parser not working

June 12th, 2018, 9:13 pm
DanielPodo
   [66 posts]

Just out of curiosity, does the regexp have to be in the order that the HTML flow occurs in?

I.e. if I want to extract the temp, description and icon, then I should have the regexp contain the code for the temp, desc and icon, in that order.

Or does it not matter ultimately?

Re: Weather Parser not working

June 12th, 2018, 9:46 pm
DanielPodo
   [66 posts]

Huh, funnily enough, I've managed to get the temperature and description, but I can't extract the icon.

Here's my code:

Code: Select all

RegExp=(?siU)<span class="description .*" data-reactid="26">(.*)</span>.*<span class="Va.*" data-reactid="37">(.*)</span>


Once I add the element for the icon at the end of this expression, it breaks the whole thing :(
User avatar

Re: Weather Parser not working

June 12th, 2018, 11:54 pm
eclectic-tech
Rainmeter Sage   [2739 posts]

DanielPodo wrote:Huh, funnily enough, I've managed to get the temperature and description, but I can't extract the icon.

Here's my code:

Code: Select all

RegExp=(?siU)<span class="description .*" data-reactid="26">(.*)</span>.*<span class="Va.*" data-reactid="37">(.*)</span>


Once I add the element for the icon at the end of this expression, it breaks the whole thing :(
The order of capture in the RegExp MUST match the order of the information on the webpage, unless you are using lookahead or lookbehind expressions.

The icon image is before the "condition" and "temp" information, so the capture code needs to be BEFORE the current RegExp;

Code: Select all

RegExp=(?siU).*data-reactid="24"><img alt=".*" height="32" title=".*" width="32" class=" " src="(.*)".*<span class="description .*" data-reactid="26">(.*)</span>.*<span class=".*" data-reactid="37">(.*)</span>

So now StringIndex1 will be the link to the icon image, StringIndex2 will be the current condition text, and StringIndex3 will be the current temperature in Fahrenheit.
User avatar

Re: Weather Parser not working

June 13th, 2018, 12:43 pm
balala
Rainmeter Sage   [6260 posts]

DanielPodo wrote:Huh, funnily enough, I've managed to get the temperature and description, but I can't extract the icon.

Below you can see a solution, to download the icon. I used a modified version of eclectic-tech's RegExp:
eclectic-tech wrote:RegExp;

Code: Select all

RegExp=(?siU).*data-reactid="24"><img alt=".*" height="32" title=".*" width="32" class=" " src="(.*)".*<span class="description .*" data-reactid="26">(.*)</span>.*<span class=".*" data-reactid="37">(.*)</span>

As we got used to, eclectic-tech's RegExp works well. However I removed the numeric values, because I'm not sure how they are changing over time, and I think would be better to not use those values into the RegExp: RegExp=(?siU)data-reactid=".*"><img alt=".*" height=".*" title=".*" width=".*" class=" " src="(.*)".*<span class="description .*" data-reactid=".*">(.*)</span>.*<span class=".*" data-reactid=".*">(\d*)</span> (I marked red what I've changed over eclectic-tech's RegExp).
Using this RegExp, here is the full code to get the description, temperature and icon:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[measureWeatherParent]
Measure=WebParser
URL=https://www.yahoo.com/news/weather/
UpdateRate=1800
RegExp=(?siU)data-reactid=".*"><img alt=".*" height=".*" title=".*" width=".*" class=" " src="(.*)".*<span class="description .*" data-reactid=".*">(.*)</span>.*<span class=".*" data-reactid=".*">(\d*)</span>
FinishAction=[!EnableMeasure "measureCurrentIcon"][!CommandMeasure "measureCurrentIcon" "Update"]

[measureWeather1]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=1

[measureWeather2]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=2

[measureWeather3]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=3

[measureWeather3Celsius]
Measure=Calc
Formula=( 5 * ( measureWeather3 - 32 ) / 9 )

[measureCurrentIcon]
Measure=WebParser
Url=[&measureWeather1]
DynamicVariables=1
Download=1
Disabled=1

[meterWeatherIcon]
meter=Image
MeasureName=measureCurrentIcon
X=0
Y=0
W=50
PreserveAspectRatio=1
LeftMouseUpAction=["bingweather://"]

[meterWeatherInfo]
meter=String
MeterStyle=SmallText | BigSkinTextFormat
MeasureName=measureWeather2
MeasureName2=measureWeather3
MeasureName3=measureWeather3Celsius
X=0r
Y=0R
Padding=15,5,15,5
Text=%1#CRLF#%2 [\x0366] F (%3 [\x0366] C)
SolidColor=255,255,255,120

I added a Calc measure ([measureWeather3Celsius]) to calculate the temperature in Celsius degrees, beside Fahrenheit. If you don't need it, you can simply remove it (along with the appropriate MeasureName3 option in the [meterWeatherInfo] String meter) and modify the Text option of the same [meterWeatherInfo] meter.

Re: Weather Parser not working

June 13th, 2018, 4:34 pm
DanielPodo
   [66 posts]

I've cleaned up your code just a touch and this is my final widget:

Code: Select all

[measureWeatherParent]
Measure=WebParser
URL=https://www.yahoo.com/news/weather/
UpdateRate=1800
RegExp=(?siU)data-reactid=".*"><img alt=".*" height=".*" title=".*" width=".*" class=" " src="(.*)".*<span class="description .*" data-reactid=".*">(.*)</span>.*<span class=".*" data-reactid=".*">(\d*)</span>
ErrorString="lol you dun fukd up"
FinishAction=[!EnableMeasure "measureCurrentIcon"][!CommandMeasure "measureCurrentIcon" "Update"]

[measureWeatherIcon]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=1

[measureWeatherDescription]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=2
Substitute="":"..."

[measureWeatherTemperature]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=3
Substitute="":"..."

[measureCurrentIcon]
Measure=WebParser
Url=[&measureWeatherIcon]
DynamicVariables=1
Download=1
Disabled=1

[ConvertFahrenToCelsius]
Measure=Calc
Formula=round((([measureWeatherTemperature]-32)*5/9), 1)
DynamicVariables=1

; ----------------------------------
; METERS
; ----------------------------------

[meterWeatherIcon]
meter=Image
MeasureName=measureCurrentIcon
W=48
PreserveAspectRatio=1
LeftMouseUpAction=["bingweather://"]

[meterWeatherInfo]
meter=String
MeterStyle=SmallText | BigSkinTextFormat
MeasureName=measureWeatherDescription
MeasureName2=measureWeatherTemperature
MeasureName3=ConvertFahrenToCelsius
Text=%3°C (%2°F)#CRLF#%1


I already had a Fahrenheit to Celsius conversion, but thanks anyway :) I hope this looks OK? One small annoyance I have at the moment is that the ConvertFahrenToCelsius measure reads 0 until the webParser is done loading, is there a neat way I can get it to read "..." similar to the other two meters until it's ready?

The order of capture in the RegExp MUST match the order of the information on the webpage, unless you are using lookahead or lookbehind expressions.


Thanks, I should have realised the answer was yes before I asked this question. :?
User avatar

Re: Weather Parser not working

June 13th, 2018, 5:38 pm
balala
Rainmeter Sage   [6260 posts]

DanielPodo wrote:I hope this looks OK? One small annoyance I have at the moment is that the ConvertFahrenToCelsius measure reads 0 until the webParser is done loading, is there a neat way I can get it to read "..." similar to the other two meters until it's ready?

As you noticed, there is an error message in the log. In the very first moment the [measureWeatherTemperature] WebParser measure doesn't return 0, but the empty string. This is why the error appears. But that's extremely simple to avoid: simply remove the brackets from the name of the measure in the Formula option of the Calc measure: Formula=Round((( measureWeatherTemperature - 32 ) * 5 / 9 ), 1). This step also has the advantage that you can remove the DynamicVariables=1 option as well from the measure. See that in this case, while the WebParser measure doesn't return a value yet, the [ConvertFahrenToCelsius] measure returns -18, which is 0 (the value of the [ConvertFahrenToCelsius] measure used in the Calc measure) converted to Celsius.

Re: Weather Parser not working

June 14th, 2018, 12:01 pm
DanielPodo
   [66 posts]

balala wrote:As you noticed, there is an error message in the log. In the very first moment the [measureWeatherTemperature] WebParser measure doesn't return 0, but the empty string. This is why the error appears. But that's extremely simple to avoid: simply remove the brackets from the name of the measure in the Formula option of the Calc measure: Formula=Round((( measureWeatherTemperature - 32 ) * 5 / 9 ), 1). This step also has the advantage that you can remove the DynamicVariables=1 option as well from the measure. See that in this case, while the WebParser measure doesn't return a value yet, the [ConvertFahrenToCelsius] measure returns -18, which is 0 (the value of the [ConvertFahrenToCelsius] measure used in the Calc measure) converted to Celsius.


Ah, it's little things like that I keep forgetting about Rainmeter. Thanks for reminding me, and thanks for the help with the weather widget!!! :17good
User avatar

Re: Weather Parser not working

June 14th, 2018, 12:09 pm
balala
Rainmeter Sage   [6260 posts]

DanielPodo wrote:Ah, it's little things like that I keep forgetting about Rainmeter. Thanks for reminding me, and thanks for the help with the weather widget!!! :17good

Glad to help.

Re: Weather Parser not working

June 16th, 2018, 6:07 pm
DanielPodo
   [66 posts]

balala wrote:Glad to help.


I figured I'd ask here since it's relevant, and no point starting another thread with a similar issue.

I'm doing a simple Location skin, using the code below, but as you probably guessed, the regexp isn't working. This should be nice and easy, but I'm not getting anything. Any reason why?

Code: Select all

[measureLocationParent]
Measure=WebParser
URL=https://mylocation.org/
UpdateRate=1800
RegExp=(?siU)<td>Country</td><td>(.*)</td>.*<td>City</td><td>(.*)</td>
ErrorString="lol you dun fukd up"

[measureLocationCountry]
Measure=WebParser
URL=[measureLocationParent]
StringIndex=1
Substitute="":"..."

[measureLocationCity]
Measure=WebParser
URL=[measureLocationParent]
StringIndex=2
Substitute="":"..."

; ----------------------------------
; METERS
; ----------------------------------

[meterLocationIcon]
meter=Image
ImageName=#@#Images\Location\Location1
LeftMouseUpAction=["bingMaps://"]

[meterLocationInfo]
meter=String
MeterStyle=SmallText | BigSkinTextFormat
MeasureName=measureLocationCity
MeasureName2=measureLocationCountry
Text=%1#CRLF#%2

Return to “Help: Rainmeter Skins”



Who is online

Users browsing this forum: No registered users and 7 guests