It is currently March 28th, 2024, 5:13 pm

Weather Parser not working

Get help with creating, editing & fixing problems with skins
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Weather Parser not working

Post by DanielPodo »

I'm tearing my hair out here. I've checked everything (net connection, the webparser skin that tests everything as well), checked the simplest websites to see if my skins are parsing at all, and they are, but for some reason this code doesn't work...(In case you guys are wondering, it's nothing to do with the MeterStyles at the bottom (they just set the colour and size, that's all)

Code: Select all

[measureWeatherParent]
Measure=WebParser
URL=https://www.timeanddate.com/weather/germany/munich
UpdateRate=30
RegExp=(?siU).*<img id="cur-weather" class="" title="" src="//c.tadst.com/gfx/w/80/(.*).png" width="80" height="80">.*<div class="h2">(.*)&nbsp;°C</div><p>(.*)</p>
ErrorString="lol you dun fukd up"

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

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

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

[measureWeather4]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=4

[meterWeatherIcon]
meter=Image
MeasureName=measureWeather1
ImagePath=#@#Images\Weather\
W=50
LeftMouseUpAction=["bingweather://"]
DynamicVariables=1

[meterWeatherInfo]
meter=String
MeterStyle=SmallText | BigSkinTextFormat
MeasureName=measureWeather2
MeasureName2=measureWeather3
MeasureName3=measureWeather4
X=0
Y=0
H=40
Text=%1#CRLF#%2%3 asfsads
The only thing that appears is the "asfsads" text, nothing else. Wtf am I doing wrong?
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Weather Parser not working

Post by ikarus1969 »

Assuming an Update=1000 in the Rainmeter-section, an UpdateRate of 30 on the webparser-measure means you access the site 30 times a second. That's definitely too much; you probably got blocked by the website.
An UpdateRate of 300 is is enough, which means to access the site every 5 minutes (again assuming a Update of 1000 in the Rainmeter section).
The weather doesn't change that often.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Weather Parser not working

Post by ikarus1969 »

Please check your regexp.
At least at the beginning there is an error. Maybe there are some more errors.

The website says

Code: Select all

s=h1>Now</div><img id=cur-weather class=mtt title="Scattered clouds." src="//c.tad
but you use in the skin

Code: Select all

<img id="cur-weather" class="" title="" src="//c.tadst.com/gfx/w/80/(.*).png" wid
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Weather Parser not working

Post by balala »

ikarus1969 wrote:Assuming an Update=1000 in the Rainmeter-section, an UpdateRate of 30 on the webparser-measure means you access the site 30 times a second. That's definitely too much;
No, at all. I'm sorry, but you're wrong here ikarus1969.
The site is accessed once per 30 seconds (which is still probably too much). The update period of the parent WebParser measure is: Update x UpdateRate x UpdateDivider and is expressed into milliseconds, because Update is expressed so. So, with UpdateRate=30, you get: 1000 x 30 x 1 = 30000 milliseconds = 30 seconds (if not specified, the value of the UpdateDivider is 1, which is the default value.
You can find some details here: https://docs.rainmeter.net/tips/update-guide/
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Weather Parser not working

Post by balala »

DanielPodo wrote:The only thing that appears is the "asfsads" text, nothing else. Wtf am I doing wrong?
The used RegExp is wrong.
Looking at the initial code, I think you wanted to get the current temperature and description, along with the current icon, right? If so, I have a remark: in the RegExp option of the parent WebParser measure ([measureWeatherParent]), you had used three times the (.*) identifier (so, you parse three strings), but in the child measures, you have the StringIndex options up to 4 (in the [measureWeather4] measure). This doesn't make the skin (measures) to fail, but it's wrong either.
I rewrote the involved measures, to get what I think you wanted to get. I also added a measure to download the appropriate icon, because if the site provides the icon, I think it is better to download it, instead of having them stored on the hard disk. The initially disabled [measureCurrentIcon] measure does exactly this: downloads the icon. Then this downloaded icon is used by the [meterWeatherIcon] Image meter.
If you want something more to parse, let us know, to can help you with that, too. For now here is the rewritten code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[measureWeatherParent]
Measure=WebParser
URL=https://www.timeanddate.com/weather/germany/munich
UpdateRate=900
RegExp=(?siU)<img id=cur-weather class=mtt title=".*" src="(.*)" width=.* height=.*><div class=h2>(.*)</div><p>(.*)</p>
;RegExp=(?siU).*<img id="cur-weather" class="" title="" src="//c.tadst.com/gfx/w/80/(.*).png" width="80" height="80">.*<div class="h2">(.*)&nbsp;°C</div><p>(.*)</p>
ErrorString="lol you dun fukd up"
FinishAction=[!EnableMeasure "measureCurrentIcon"][!CommandMeasure "measureCurrentIcon" "Update"]

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

[measureWeather2]
Measure=WebParser
URL=[measureWeatherParent]
StringIndex=2
Substitute="&nbsp;":""

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

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

[meterWeatherInfo]
meter=String
MeterStyle=SmallText | BigSkinTextFormat
MeasureName=measureWeather2
MeasureName2=measureWeather3
X=0
Y=0
H=40
Text=%1#CRLF#%2
SolidColor=255,255,255,120

[meterWeatherIcon]
meter=Image
MeasureName=measureCurrentIcon
X=0r
Y=0R
W=50
LeftMouseUpAction=["bingweather://"]
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Weather Parser not working

Post by DanielPodo »

Hey balala, once again thanks for your help.

Yes, you're right, as an initial test I was just trying to get the icon, temperature and weather description (literally, in that order). I know I omitted the last index but I figured what's the point of getting that if just the first few aren't working!

Again, same with the update rate. I didn't bother changing it because I was testing the app (plus I had updatedivider=-1 in there too), and I'd set that to measure the weather every 20/30 minutes or so once it worked.

Your code works perfectly! Just two questions, as I'm getting back into Rainmeter after taking almost a 2 year hiatus:

Url=http:[&measureWeather1]

1. Why not simply Url=[measureWeatherParent]?
2. Why the & within the brackets? What does this do?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Weather Parser not working

Post by balala »

DanielPodo wrote:1. Why not simply Url=[measureWeatherParent]?
Because the main site returns the URL of the image without the http: prefix. I added it, because without it, the WebParser measure doesn't find the image and can't dwonload it.
DanielPodo wrote:2. Why the & within the brackets? What does this do?
Because when the name of a WebParser measure is used into the URL option of another WebParser measure (like this time), it is used dynamically as a section variable and it has to be prefixed by a & character. Details in the last paragraph here: https://docs.rainmeter.net/manual-beta/measures/webparser/#URL

Finally one question: did you get the code to work as you wanted, or there is something more to be added?
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Weather Parser not working

Post by DanielPodo »

balala wrote:Because the main site returns the URL of the image without the http: prefix. I added it, because without it, the WebParser measure doesn't find the image and can't dwonload it.

Because when the name of a WebParser measure is used into the URL option of another WebParser measure (like this time), it is used dynamically as a section variable and it has to be prefixed by a & character. Details in the last paragraph here: https://docs.rainmeter.net/manual-beta/measures/webparser/#URL

Finally one question: did you get the code to work as you wanted, or there is something more to be added?
Thanks for the explanations. Yes, it did work, but I decided to change the URL to the Yahoo weather website. Unfortunately, this meant changing the regexp and it's broken again :17angry

What exactly is wrong with my regexp?

Code: Select all

[measureWeatherParent]
Measure=WebParser
URL=https://www.yahoo.com/news/weather/
UpdateRate=1800
RegExp=(?siU)<span data-code="47" data-reactid="471"><img alt=".* height=".*" title=".*" width=".*" class=".*" src="(.*)" data-reactid="472"></span>.*<span class="Va(t)" data-reactid="37">(.*)</span>.*<span class="description Va(m) Px(2px) Fz(1.3em)--sm Fz(1.6em)" data-reactid="26">(.*)</span>
ErrorString="lol you dun fukd up"
FinishAction=[!EnableMeasure "measureCurrentIcon"][!CommandMeasure "measureCurrentIcon" "Update"]
Also, is it possible to separate the regexp with new lines, or will that mess things up?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Weather Parser not working

Post by balala »

DanielPodo wrote:Thanks for the explanations. Yes, it did work, but I decided to change the URL to the Yahoo weather website. Unfortunately, this meant changing the regexp and it's broken again :17angry
Yep, you definitely have to rewrite the RegExp.
What you would like to get from this site? There are a lot of icons, which one would you need? And what other info? Same as previously, temperature and description?
User avatar
DanielPodo
Posts: 77
Joined: March 30th, 2016, 1:50 pm

Re: Weather Parser not working

Post by DanielPodo »

balala wrote:Yep, you definitely have to rewrite the RegExp.
What you would like to get from this site? There are a lot of icons, which one would you need? And what other info? Same as previously, temperature and description?
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.

I looked at the HTML when viewing the website and selected the elements I wanted, extracted the html code and I figured I had the regexp done properly.
Post Reply