It is currently April 27th, 2024, 5:54 pm

Generate Automatic WeatherCode from IP address in use

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Generate Automatic WeatherCode from IP address in use

Post by jsmorley »

JamX wrote: October 5th, 2019, 11:28 am Although I still have the question with :
"FinishAction=[!CommandMeasure MeasureWeatherCode "Update"]

Maybe stupid question, but WHY and why at this location?"
Not a stupid question at all...

When you have a second WebParser parent measure that is using / dependent on a first WebParser parent measure, you have to account for the fact that at first, when the skin first is loaded or refreshed, they will both be executed in the first update cycle, and at that time, there won't be anything from the first one available for the second one to use. That's wouldn't be a huge problem, since by the second update cycle or so the information will be there in the first one, but since WebParser parent measures only update every 10 minutes by default, the second one won't get or use this information until then.

The FinishAction on the first parent measure will "poke" the second one when the information is available, and tell it "hey, I'm ready now, come get it!".

Now, even though this will work fine, you will in fact get one single error message RegExp matching error (-1) in the log when the skin is first loaded or refreshed. When that second parent measure tries to go out and get information, but can't since it doesn't yet have what it needs from the first. I hate transient error messages, so it can be avoided like this:

Code: Select all

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

[Variables]

[MeasureLocation]
Measure=WebParser
Url=http://ip-api.com/json
RegExp=(?siU)"city":"(.*)".*"country":"(.*)".*"regionName":"(.*)"
FinishAction=[!EnableMeasure MeasureWeatherCode][!CommandMeasure MeasureWeatherCode "Update"]

[MeasureCity]
Measure=WebParser
URL=[MeasureLocation]
StringIndex=1

[MeasureCountry]
Measure=WebParser
URL=[MeasureLocation]
StringIndex=2

[MeasureRegion]
Measure=WebParser
URL=[MeasureLocation]
StringIndex=3

[MeasureWeatherCode]
Measure=WebParser
Url=http://wxdata.weather.com/wxdata/search/search?where=[&MeasureCity] [&MeasureRegion] [&MeasureCountry]
Disabled=1
DynamicVariables=1
RegExp=(?siU).*<loc id="(.*)"
FinishAction=[!UpdateMeter *][!Redraw]

[MeasureCode]
Measure=WebParser
URL=[MeasureWeatherCode]
StringIndex=1

[MeterBack]
Meter=Shape
Shape=Rectangle 0.5,0.5,300,130 | StrokeWidth 1 | Stroke Color 150,150,150,255 | Fill Color 47,47,47,120

[MeterLocation]
Meter=String
MeasureName=MeasureCity
MeasureName2=MeasureRegion
MeasureName3=MeasureCountry
MeasureName4=MeasureCode
X=(300/2)
Y=(130/2)
FontSize=14
FontColor=255,255,255,255
AntiAlias=1
StringAlign=CenterCenter
InlineSetting=Size | 12
InlinePattern=#CRLF#.*$
InlineSetting2=Color | 106,255,87,255 
InlinePattern2=#CRLF#.*$
Text=%1#CRLF#%2#CRLF#%3#CRLF##CRLF#%4

1.jpg


So you just don't let the second measure execute at all until the first one is done. Then you tell it "Ok, wake up and go do your thing, right now!".
You do not have the required permissions to view the files attached to this post.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Generate Automatic WeatherCode from IP address in use

Post by JamX »

What if you have 3 parents, should it be like this? :

The first gives the city, region and country
The second gives the weathercode
The third gives the weather information for this weathercode

Code: Select all

;---------------------------------------------
[MeasureIPLocation]
Measure=WebParser
Url=http://ip-api.com/json
RegExp=(?siU)"city":"(.*)","country":"(.*)".*,"regionName":"(.*)"
;FinishAction=[!CommandMeasure MeasureWeatherCodeLocationRSS "Update"]
FinishAction=[!EnableMeasure MeasureWeatherCodeLocationRSS][!CommandMeasure MeasureWeatherCodeLocationRSS "Update"]

[MeasureIPCity]
Measure=WebParser
Url=[MeasureIPLocation]
StringIndex=1

[MeasureIPCountry]
Measure=WebParser
Url=[MeasureIPLocation]
StringIndex=2

[MeasureIPRegion]
Measure=WebParser
URL=[MeasureIPLocation]
StringIndex=3

[MeasureWeatherCodeLocationRSS]
Measure=WebParser
Url=http://wxdata.weather.com/wxdata/search/search?where=[&MeasureIPCity] [&MeasureIPRegion] [&MeasureIPCountry]
DynamicVariables=1
RegExp=(?siU).*<loc id="(.*)"
;FinishAction=[!CommandMeasure MeasureWeatherRSS "Update"]
FinishAction=[!EnableMeasure MeasureWeatherRSS][!CommandMeasure MeasureWeatherRSS "Update"]

[MeasureWeatherCode]
Measure=WebParser
URL=[MeasureWeatherCodeLocationRSS]
StringIndex=1

;------------------------------------------

[MeasureWeatherRSS]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=3600
Url=http://wxdata.weather.com/wxdata/weather/local/[&MeasureWeatherCode]?cc=*&unit=#WeatherUnit#&dayf=6
;http://wxdata.weather.com/wxdata/weather/local/NLXX0272?cc=*&unit=m&dayf=6
RegExp=(?siU)<weather ver="(.*)">(.*)<tmp>(.*)</tmp>(.*)<t>(.*)</t>(.*)<icon>(.*)</icon>(.*)<d>(.*)</d>.*<wind>.*<s>(.*)</s>.*<d>(.*)</d>.*<day d="1" t="(.*)" dt="(.*)">(.*)<hi>(.*)</hi>(.*)<low>(.*)</low>(.*)<icon>(.*)</icon>(.*)<t>(.*)</t>(.*).*<wind>.*<s>(.*)</s>.*<d>(.*)</d>.*<day d="2" t="(.*)" dt="(.*)">(.*)<hi>(.*)</hi>(.*)<low>(.*)</low>(.*)<icon>(.*)</icon>(.*)<t>(.*)</t>(.*).*<wind>.*<s>(.*)</s>.*<d>(.*)</d>.*<day d="3" t="(.*)" dt="(.*)">(.*)<hi>(.*)</hi>(.*)<low>(.*)</low>(.*)<icon>(.*)</icon>(.*)<t>(.*)</t>(.*).*<wind>.*<s>(.*)</s>.*<d>(.*)</d>.*<day d="4" t="(.*)" dt="(.*)">(.*)<hi>(.*)</hi>(.*)<low>(.*)</low>(.*)<icon>(.*)</icon>(.*)<t>(.*)</t>(.*).*<wind>.*<s>(.*)</s>.*<d>(.*)</d>
DynamicVariables=1

;--------------------------------

[MeasureWeatherTemp]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureWeatherRSS]
StringIndex=3
When I do like this I get 2 RegExp matching error (-1) in the log file
User avatar
balala
Rainmeter Sage
Posts: 16178
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Generate Automatic WeatherCode from IP address in use

Post by balala »

JamX wrote: October 6th, 2019, 9:13 am When I do like this I get 2 RegExp matching error (-1) in the log file
You have to disable the parent WebParser measures, except the first one.
[MeasureIPLocation] get first its value. Only when it and its child measures got their value, the second parent WebParser measure ([MeasureWeatherCodeLocationRSS]) should be enabled and updated. This is done by the bangs of the FinishAction option of [MeasureIPLocation]. But if [MeasureWeatherCodeLocationRSS] isn't disabled at the very first moment, it tries to get the required information. But because its URL option is properly set only when [MeasureIPLocation] got its value, this gives you the error message.
Same discussion for the other pair of parent WebParser measures, [MeasureWeatherCodeLocationRSS] and [MeasureWeatherRSS].
The solution is to add a Disabled=1 option to both parent WebParser measures, [MeasureWeatherCodeLocationRSS] and [MeasureWeatherRSS].
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Generate Automatic WeatherCode from IP address in use

Post by JamX »

That did the trick.
I forgot to put the disables=1 command into the code. :?
All code is now error free!

So the update rate is set by the 1st webparser parent ( every 10 minutes )
Every 10 minutes City, region and country are parsed followed by WeatherCode and then all weather Data

But because my computer does not "move" - City, region and country based on IP would be OK when 1 time parsed.
WeatherCode corresponding to city, region and country would also be OK when 1time parsed.
Only the weather changes and should be parsed (let say) every 5 minutes.

Maybe this is overkill what I suggest but is this also possible without errors?
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Generate Automatic WeatherCode from IP address in use

Post by jsmorley »

JamX wrote: October 6th, 2019, 3:24 pm That did the trick.
I forgot to put the disables=1 command into the code. :?
All code is now error free!

So the update rate is set by the 1st webparser parent ( every 10 minutes )
Every 10 minutes City, region and country are parsed followed by WeatherCode and then all weather Data

But because my computer does not "move" - City, region and country based on IP would be OK when 1 time parsed.
WeatherCode corresponding to city, region and country would also be OK when 1time parsed.
Only the weather changes and should be parsed (let say) every 5 minutes.

Maybe this is overkill what I suggest but is this also possible without errors?
You can't really set a WebParser measure to only measure "once", but there is no reason why you couldn't set a really large UpdateRate on the first two measures. Something like UpdateRate=86400 for instance, which is once a day.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Generate Automatic WeatherCode from IP address in use

Post by JamX »

Since the first webparser is the "trigger" for the second and the second the trigger for the third, is putting a very large updaterate value at these location also impacting the updatrate for the third parser?, which I want to parse more frequent.

If not, this implies that the disabled=1 command is only 1 time valid.
Am I correct in this assumption.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Generate Automatic WeatherCode from IP address in use

Post by jsmorley »

JamX wrote: October 6th, 2019, 3:39 pm Since the first webparser is the "trigger" for the second and the second the trigger for the third, is putting a very large updaterate value at these location also impacting the updatrate for the third parser?, which I want to parse more frequent.

If not, this implies that the disabled=1 command is only 1 time valid.
Am I correct in this assumption.
All WebParser measures will update (in the sense of going out to the internet) once every UpdateRate, which by default is every 10 minutes, but can be anything you like. The first two measures will "turn on" the third one the first time they succeed, and from then on, the third one will update every 10 minutes, no matter what you have as an UpdateRate on the first two.

You are correct in your assumption. Once you !EnableMeasure a measure with Disabled=1 on it, it is enabled from then on, unless you turn it back off with !DisableMeasure.

So if you set UpdateRate=86400 on the first two, and just leave UpdateRate off entirely on the third one, it will properly work. It will check your IP and get the weather location code once when the skin is loaded/refreshed and then once a day, and will get the weather once when the skin is loaded/refreshed and every 10 minutes thereafter.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Generate Automatic WeatherCode from IP address in use

Post by JamX »

Thanks for the info.

The skin works like a charm now thanks to you and balala :bow:

Keep up the good work!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Generate Automatic WeatherCode from IP address in use

Post by jsmorley »

JamX wrote: October 6th, 2019, 3:55 pm Thanks for the info.

The skin works like a charm now thanks to you and balala :bow:

Keep up the good work!

Sure thing. To be honest, if I was writing a skin for any kind of distribution, I'd be tempted to let the skin check the IP and location code just as often anyway. You might fire up your VPN, or take your laptop to the local Starbucks and your IP could in fact change. The work it is doing checking those is trivial.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Generate Automatic WeatherCode from IP address in use

Post by JamX »

TRUE.!
Sure thing. To be honest, if I was writing a skin for any kind of distribution, I'd be tempted to let the skin check the IP and location code just as often anyway. You might fire up your VPN, or take your laptop to the local Starbucks and your IP could in fact change. The work it is doing checking those is trivial.
ByTheWay: is it possible to see or check how often an update takes place. (Time)
in the log file I only see the initial loading of the skin