It is currently April 8th, 2020, 2:39 pm

Some help with coding.

Help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 10094
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

JamX wrote:
March 20th, 2020, 5:25 pm
I had to rewrite some code to make it work but the final part where the MeasureCurrentLatitude and MeasureCurrentLongitude is assigned to the URL part does not work.

Also I get Calc: Extra operation error for MeasureCurrentLatitude and MeasureCurrentLongitude at skin refresh
This is caused by the fact that when the skin is refreshed / loaded, the [MeasureLatitude] and [MeasureLongitude] measures don't have yet a value, because they need a few moments until get their values. So their values are empty, but the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are waiting for numeric values. This fact gives the error.
My bad, should have been realize this will happen. But didn't check the log in time. Sorry.
To fix this, just add the following two options to both measures [MeasureLatitude] and [MeasureLongitude]:

Code: Select all

[MeasureLatitude]
...
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureLongitude]
...
RegExpSubstitute=1
Substitute="^$":"#Longitude#"
Using these options ensures the measures are not empty even on the very first moment after refresh.

JamX wrote:
March 20th, 2020, 5:25 pm
I had to rewrite some code to make it work but the final part where the MeasureCurrentLatitude and MeasureCurrentLongitude is assigned to the URL part does not work.
Note that with the measures posted by you, when the value returned by the [MeasureAdapter] measure is GOOSEVPN, the VPNOn variable is set to 1 and the values returned by the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are #Latitude# and #Longitude# accordingly. If the [MeasureAdapter] measure doesn't match GOOSEVPN, the VPNOn variable is set to 0 and this time the values returned by the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are [MeasureLatitude] and [MeasureLongitude] accordingly. I think this way, this is not exactly ok. Is it?
User avatar
balala
Rainmeter Sage
Posts: 10094
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

JamX wrote:
March 20th, 2020, 5:32 pm
The Calc error I solved this way
No need to disable the Calc measures. See my previous post above.
JamX wrote:
March 20th, 2020, 5:32 pm
the URL assignment still does not work.
Same for this question as well: see the above reply.
User avatar
JamX
Posts: 108
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

Note that with the measures posted by you, when the value returned by the [MeasureAdapter] measure is GOOSEVPN, the VPNOn variable is set to 1 and the values returned by the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are #Latitude# and #Longitude# accordingly. If the [MeasureAdapter] measure doesn't match GOOSEVPN, the VPNOn variable is set to 0 and this time the values returned by the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are [MeasureLatitude] and [MeasureLongitude] accordingly. I think this way, this is not exactly ok. Is it?
This is exactly what I need.
VPN OFF; MeasureCurrentLatitude and MeasureCurrentLongitude to be the locations lat and long base on IP address. [MeasureLatitude] and [MeasureLongitude] accordingly.
VPN ON; MeasureCurrentLatitude and MeasureCurrentLongitude to be my standard Locations coordinates. #Latitude# and #Longitude# accordingly.

So this is what I've got so far:

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

VPNOn=0

;--- Lat & Long for Landgraaf NL ---
Latitude=50.8871
Longitude=6.0116


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

[MeasureLocationIP]
Measure=WebParser
URL=https://ipapi.co/json
RegExp="(?siU)"city": "(.*)".*"region": "(.*)".*"country_name": "(.*)",.*"latitude": (.*),.*"longitude": (.*),.*"
UpdateRate=#UpdateRate#
FinishAction=[!UpdateMeasureGroup GeocodeGroup]
DynamicVariables=1

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!UpDateMeasure "MeasureCurrentLatitude"][!UpDateMeasure "MeasureCurrentLongitude"][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@ForecastAll"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!UpDateMeasure "MeasureCurrentLatitude"][!UpDateMeasure "MeasureCurrentLongitude"][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@ForecastAll"]

[MeasureCurrentLatitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLatitude] + (#VPNOn#  * #Latitude# )
DynamicVariables=1

[MeasureCurrentLongitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLongitude] + (#VPNOn#  * #Longitude# )
DynamicVariables=1
When VPNon = 1 I get.
MeasureLatitude = 52.3109 (VPN location latitude)
MeasureLongitude = 4.9453 (VPN location longitude)
MeasureAdapter=GOOSEVPN
MeasureCurrentLatitude=50.8871
MeasureCurrentLongitude=6.0116
So this is OK
Capture1.JPG
The URLCurrent and URLForecast are correct
https://weather.com/en-GB/weather/today/l/50.8871,6.0116
Capture2.JPG
When VPNon = 0 the returned Lat and Long are OK
MeasureLatitude = 50.8871 (My IP location latitude)
MeasureLongitude = 6.0116 (My IP location longitude)
MeasureAdapter=Realtek PCIe .....
MeasureCurrentLatitude=50.8871
MeasureCurrentLongitude=6.0116
This is also OK
Capture3.JPG
But the URLCurrent and URLForecast are NOT OK
Capture4.JPG
https://weather.com/en-GB/weather/today/l/50.8871,50.8871
The longitude value is NOT OK (Latitude value is used)

Both VPNon situations use the same [!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"] code so why do I get when VPNon=0 correct MeasureCurrentLongitude but wrong Longitude assignment in the URL???
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 10094
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

JamX wrote:
March 21st, 2020, 9:48 am
But the URLCurrent and URLForecast are NOT OK
Capture4.JPG
https://weather.com/en-GB/weather/today/l/50.8871,50.8871
But what are the actual values of the urlcurrent and urlforecast variables? I suppose the provided code is not the complete code, the [Variables] section (where probably the variables are set) is not included. Please take a look to both variables. I suppose they are mistakenly set to:

urlcurrent=https://weather.com/en-GB/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLatitude], respectively:
urlforecast=https://weather.com/en-GB/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLatitude],

instead of:

urlcurrent=https://weather.com/en-GB/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude] and:
urlforecast=https://weather.com/en-GB/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude].

Please check. I suppose this because in the posted image I see the same 50.8871 value two times, one after the other, so probably the same value is repeated.
User avatar
JamX
Posts: 108
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

balala wrote:
March 21st, 2020, 11:27 am
But what are the actual values of the urlcurrent and urlforecast variables? I suppose the provided code is not the complete code, the [Variables] section (where probably the variables are set) is not included. Please take a look to both variables. I suppose they are mistakenly set to:

urlcurrent=https://weather.com/en-GB/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLatitude], respectively:
urlforecast=https://weather.com/en-GB/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLatitude],

instead of:

urlcurrent=https://weather.com/en-GB/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude] and:
urlforecast=https://weather.com/en-GB/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude].

Please check. I suppose this because in the posted image I see the same 50.8871 value two times, one after the other, so probably the same value is repeated.

The variables are shown as:

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

VPNOn=0

;--- Lat & Long for Landgraaf NL ---
Latitude=50.8871
Longitude=6.0116
The !SetVariables are set as

Code: Select all

[!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"
Which is OK also

This is the complete code

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

VPNOn=0

;--- Lat & Long for Landgraaf NL ---
Latitude=50.8871
Longitude=6.0116


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

[MeasureLocationIP]
Measure=WebParser
URL=https://ipapi.co/json
RegExp="(?siU)"city": "(.*)".*"region": "(.*)".*"country_name": "(.*)",.*"latitude": (.*),.*"longitude": (.*),.*"
UpdateRate=#UpdateRate#
FinishAction=[!UpdateMeasureGroup GeocodeGroup]
DynamicVariables=1

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!UpDateMeasure "MeasureCurrentLatitude"][!UpDateMeasure "MeasureCurrentLongitude"][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@ForecastAll"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!UpDateMeasure "MeasureCurrentLatitude"][!UpDateMeasure "MeasureCurrentLongitude"][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@ForecastAll"]

[MeasureCurrentLatitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLatitude] + (#VPNOn#  * #Latitude# )
DynamicVariables=1

[MeasureCurrentLongitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLongitude] + (#VPNOn#  * #Longitude# )
DynamicVariables=1
User avatar
Yincognito
Posts: 1152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Some help with coding.

Post by Yincognito »

JamX wrote:
March 21st, 2020, 12:18 pm
The variables are shown as:

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

VPNOn=0

;--- Lat & Long for Landgraaf NL ---
Latitude=50.8871
Longitude=6.0116
The !SetVariables are set as

Code: Select all

[!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"
Which is OK also

This is the complete code

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

VPNOn=0

;--- Lat & Long for Landgraaf NL ---
Latitude=50.8871
Longitude=6.0116


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

[MeasureLocationIP]
Measure=WebParser
URL=https://ipapi.co/json
RegExp="(?siU)"city": "(.*)".*"region": "(.*)".*"country_name": "(.*)",.*"latitude": (.*),.*"longitude": (.*),.*"
UpdateRate=#UpdateRate#
FinishAction=[!UpdateMeasureGroup GeocodeGroup]
DynamicVariables=1

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5
RegExpSubstitute=1
Substitute="^$":"#Latitude#"

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!UpDateMeasure "MeasureCurrentLatitude"][!UpDateMeasure "MeasureCurrentLongitude"][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@ForecastAll"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!UpDateMeasure "MeasureCurrentLatitude"][!UpDateMeasure "MeasureCurrentLongitude"][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureCurrentLatitude],[MeasureCurrentLongitude]"][!EnableMeasure "@ForecastAll"]

[MeasureCurrentLatitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLatitude] + (#VPNOn#  * #Latitude# )
DynamicVariables=1

[MeasureCurrentLongitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLongitude] + (#VPNOn#  * #Longitude# )
DynamicVariables=1
The same lat and long happen because you have set the same Substitute="^$":"#Latitude#" in both your substitutes from [MeasureLatitude] and [MeasureLongitude]. Correcting the latter should fix this ... although this means that in this particular case you are in effect getting the empty string for both (not sure if this is what you expect).

EDIT: Also, the skins doesn't have any meters included, which leads Rainmeter to unload it as a result. Just saying...
User avatar
JamX
Posts: 108
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

:? stupid me.
User avatar
Yincognito
Posts: 1152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Some help with coding.

Post by Yincognito »

JamX wrote:
March 21st, 2020, 2:41 pm
:? stupid me.
Yeah, don't worry - it happens to all of us once in a while. That's one of the side effects of copy-paste, after all: sometimes you forget to modify the text you just pasted... :D
User avatar
JamX
Posts: 108
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

Still I have 1 strange item left which I can not explain.
When The VPN is ON and I refresh the skin the MeasureCurrentLatitude and MeasureCurrentLongitude display the lat and long of the variables I've declared. That's OK.

When I turn VPN OFF MeasureCurrentLatitude and MeasureCurrentLongitude get the values VPN lat and Long and at the 2nd refresh of the skin you'll see these, wrong, measurements in the weather data
In the 3rd refresh the correct data is displayed.

See movie: http://www.filefactory.com/file/7j43cn8eya7p/Project.mp4

Here is the skin with meters.
weather_.rmskin
You do not have the required permissions to view the files attached to this post.
Last edited by JamX on March 21st, 2020, 4:15 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 10094
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

Yincognito wrote:
March 21st, 2020, 12:57 pm
The same lat and long happen because you have set the same Substitute="^$":"#Latitude#" in both your substitutes from [MeasureLatitude] and [MeasureLongitude]. Correcting the latter should fix this ... although this means that in this particular case you are in effect getting the empty string for both (not sure if this is what you expect).
Yep, didn't notice this, even if this mistake has been introduced earlier.
Congrats, good observation...