It is currently March 29th, 2024, 9:11 am

Some help with coding.

Get help with creating, editing & fixing problems with skins
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Some help with coding.

Post by JamX »

Normally I get the latitude and longitude for my weather skin by using the IP address.

Yesterday I installed a VPN program and this changes my IP address to whatever I select based on the selection I make in the program.
This causes the weather skin to display the wrong measures.

With

Code: Select all

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
I can see the name of the adapter in use. I my case "GOOSEVPN" if VPN = "ON"

Now I want to overwrite the MeasureLatitude and MeasureLongitude
IfCondition=MeasureAdapter=GOOSEVPN
IfTrueAction=[!SetOption MeasureLatitude "50.8871"][!SetOption MeasureLongitude "6.0116"]


But this does not work????

Anybody an idea how to fix this?

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

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

;--- Measure Location Latitude and Longitude by IP ---

[MeasureLocationIP]
Measure=WebParser
URL=https://ipapi.co/json
RegExp="(?siU)"city": "(.*)".*"region": "(.*)".*"country_name": "(.*)",.*"latitude": (.*),.*"longitude": (.*),.*""
UpdateRate=#UpdateRate#
FinishAction=[!UpdateMeasureGroup GeocodeGroup][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureLatitude],[MeasureLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureLatitude],[MeasureLongitude]"][!EnableMeasure "@ForecastAll"]
DynamicVariables=1

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5

;--- Replace Location Latitude and Longitude by defaults when VPN is "ON" ---

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
IfCondition=MeasureAdapter=GOOSEVPN
IfTrueAction=[!SetOption MeasureLatitude "50.8871"][!SetOption MeasureLongitude "6.0116"]
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

JamX wrote: March 20th, 2020, 8:34 am Now I want to overwrite the MeasureLatitude and MeasureLongitude
IfCondition=MeasureAdapter=GOOSEVPN
IfTrueAction=[!SetOption MeasureLatitude "50.8871"][!SetOption MeasureLongitude "6.0116"]


But this does not work????

Anybody an idea how to fix this?
IfCondition is entirely numeric, which means that it can't be used to check string matches. For this you have to use IfMatch. So replace the IfCondition and IfTrueAction options of the [MeasureAdapter] measure with the following ones:

Code: Select all

[MeasureAdapter]
...
IfMatch=GOOSEVPN
IfMatchAction=[!SetOption MeasureLatitude "50.8871"][!SetOption MeasureLongitude "6.0116"]
But note that the above !SetOption bangs are used incorrectly, because !SetOption needs (at least) three parameters:
  • Meter/Measure (required): Name of the meter or measure section.
  • Option (required): Name of the option to be changed.
  • Value (required): New value to be set.
If you know for sure what values do you have to use for geographical coordinates, there is not needed to create measures. Just create for instance two variables (eg Latitude=50.8871 and Longitude=6.0116) into the [Variables] section and use them. If they are static, not even the DynamicVariables=1 option doesn't have to be set on the sections where are you using these variables.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

balala wrote: March 20th, 2020, 9:34 am IfCondition is entirely numeric, which means that it can't be used to check string matches. For this you have to use IfMatch. So replace the IfCondition and IfTrueAction options of the [MeasureAdapter] measure with the following ones:

Code: Select all

[MeasureAdapter]
...
IfMatch=GOOSEVPN
IfMatchAction=[!SetOption MeasureLatitude "50.8871"][!SetOption MeasureLongitude "6.0116"]
But note that the above !SetOption bangs are used incorrectly, because !SetOption needs (at least) three parameters:
I've replaced it with but I still get the lat and long from the VPN IP address:

Code: Select all

[MeasureAdapter]
...
IfMatch=GOOSEVPN
IfMatchAction=[!SetOption MeasureLatitude stringindex "50.8871"][!SetOption MeasureLongitude stringindex "6.0116"]
The problem is I do not know what "Option (required): Name of the option to be changed." I have to use.
StringIndex, Measure, ??, they all do not give me the result I need.

Code: Select all

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5
If you know for sure what values do you have to use for geographical coordinates, there is not needed to create measures. Just create for instance two variables (eg Latitude=50.8871 and Longitude=6.0116) into the [Variables] section and use them. If they are static, not even the DynamicVariables=1 option doesn't have to be set on the sections where are you using these variables.
I need the MeasureLatitude and MeasureLongitude if I do not use VPN (turn OFF).
VPN OFF; I want the locations latitude and longitude base on IP address.
VPN ON; I want MeasureLatitude and MeasureLongitude to be my standard Locations coordinates.

The 2 measures are used in the URL command: URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureLatitude],[MeasureLongitude]"
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

I think I have it working.
Probably not the best coding but for now it works.

Code: Select all

[Variables]
Language=en-GB
UpdateRate=600

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

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

;--- Check VPN or not ---

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

;--- Measure Location Latitude and Longitude by IP ---

[MeasureLocationIP]
Measure=WebParser
URL=https://ipapi.co/json
RegExp="(?siU)"city": "(.*)".*"region": "(.*)".*"country_name": "(.*)",.*"latitude": (.*),.*"longitude": (.*),.*""
UpdateRate=#UpdateRate#
FinishAction=[!UpdateMeasureGroup GeocodeGroup][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureLatitude],[MeasureLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureLatitude],[MeasureLongitude]"][!EnableMeasure "@ForecastAll"]DynamicVariables=1
Disabled=1

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

JamX, when you posted you reply, I had written my reply as well, so here it is:
JamX wrote: March 20th, 2020, 11:30 am I've replaced it with but I still get the lat and long from the VPN IP address:

Code: Select all

[MeasureAdapter]
...
IfMatch=GOOSEVPN
IfMatchAction=[!SetOption MeasureLatitude stringindex "50.8871"][!SetOption MeasureLongitude stringindex "6.0116"]
50.8871 and 6.0116 are not the StringIndex values. They are the values which the measures should return. If you anyway want to use some measures and those values are static, use Calc measures instead of WebParser:

Code: Select all

[MeasureLatitude]
Measure=Calc
Formula=50.8871

[MeasureLongitude]
Measure=Calc
Formula=6.0116
StringIndex is always integer. It is the index of the string returned by the parent WebParser measure. In most cases a parent WebParser measure returns more strings and the child measures are returning each one of these values. The index of the value returned by any of the child measures is the StringIndex. Important is this has to be an integer, up to 99.
JamX wrote: March 20th, 2020, 11:30 am The problem is I do not know what "Option (required): Name of the option to be changed." I have to use.
StringIndex, Measure, ??, they all do not give me the result I need.
No way to change the Measure type with a !SetOption bang. This is not possible at all!
JamX wrote: March 20th, 2020, 11:30 am I need the MeasureLatitude and MeasureLongitude if I do not use VPN (turn OFF).
VPN OFF; I want the locations latitude and longitude base on IP address.
VPN ON; I want MeasureLatitude and MeasureLongitude to be my standard Locations coordinates.

The 2 measures are used in the URL command: URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureLatitude],[MeasureLongitude]"
I'd use the following approach. You have there the [MeasureLatitude] and [MeasureLongitude] measures, which return the geographical coordinates when VPN is on. If it's not, you have to use the preset values, right?
if this is right, replace the previously existing IfMatch (or IfCondition) options of the [MeasureAdapter] measure as it follows:

Code: Select all

[MeasureAdapter]
...
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!UpdateMeasure "MeasureVPN"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!UpdateMeasure "MeasureVPN"]
Add the appropriate geographical coordinates as variables to the [Variables] section:

Code: Select all

[Variables]
...
Latitude=50.8871
Longitude=6.0116
And finally create the following two Calc measures:

Code: Select all

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

[MeasureCurrentLongitude]
Measure=Calc
Formula=( #VPNOn# * [MeasureLongitude] + ( 1 - #VPNOn# ) * #Longitude# )
DynamicVariables=1
The above [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are returning the appropriate geographical coordinates:
  • If VPN is on, the value of the VPNOn variables is set to 1 and the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are returning the values of the [MeasureLatitude] and [MeasureLongitude] measures accordingly.
  • If on the other hand VPN is off, VPNOn is set to 0 and the values returned by the [MeasureCurrentLatitude] and [MeasureCurrentLongitude] measures are equal to #Latitude# and #Longitude#, accordingly.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

elegant solution. :thumbup:
But where do I see/find "[!UpdateMeasure "MeasureVPN"]" in the coding

Thanks for the support
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

JamX wrote: March 20th, 2020, 2:21 pm But where do I see/find "[!UpdateMeasure "MeasureVPN"]" in the coding
It seems I messed it up something. Working on it.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Some help with coding.

Post by balala »

balala wrote: March 20th, 2020, 2:47 pm It seems I messed it up something. Working on it.
Here is the code. I can't try it out, so just hope it does work. Please let me know if it does.

Code: Select all

[Variables]
VPNOn=0
Latitude=50.8871
Longitude=6.0116

[MeasureLocationIP]
Measure=WebParser
URL=https://ipapi.co/json
RegExp="(?siU)"city": "(.*)".*"region": "(.*)".*"country_name": "(.*)",.*"latitude": (.*),.*"longitude": (.*),.*""
UpdateRate=#UpdateRate#
FinishAction=[!UpdateMeasureGroup GeocodeGroup][!SetVariable URLCurrent "https://weather.com/#Language#/weather/today/l/[MeasureLatitude],[MeasureLongitude]"][!EnableMeasure "@CurrentAll"][!SetVariable URLForecast "https://weather.com/#Language#/weather/tenday/l/[MeasureLatitude],[MeasureLongitude]"][!EnableMeasure "@ForecastAll"]DynamicVariables=1
Disabled=1

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5

[MeasureAdapter]
...
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!UpdateMeasure "MeasureCurrentLatitude"][!UpdateMeasure "MeasureCurrentLongitude"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!UpdateMeasure "MeasureCurrentLatitude"][!UpdateMeasure "MeasureCurrentLongitude"]

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

[MeasureCurrentLongitude]
Measure=Calc
Formula=( #VPNOn# * [MeasureLongitude] + ( 1 - #VPNOn# ) * #Longitude# )
DynamicVariables=1
Weird is the Disabled=1 option on the [MeasureLocationIP] measure. Maybe you have to remove it.
Sorry for the confusion.
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

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

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

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!UpdateMeasure "MeasureCurrentLatitude"][!UpdateMeasure "MeasureCurrentLongitude"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!UpdateMeasure "MeasureCurrentLatitude"][!UpdateMeasure "MeasureCurrentLongitude"]

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

[MeasureCurrentLongitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLongitude] + (#VPNOn#  * #Longitude# )
DynamicVariables=1
FinishAction=[!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"]
User avatar
JamX
Posts: 207
Joined: October 4th, 2019, 2:46 pm

Re: Some help with coding.

Post by JamX »

The Calc error I solved this way but the URL assignment still does not work.

Code: Select all

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

[MeasureLatitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=4

[MeasureLongitude]
Group=GeocodeGroup
Measure=WebParser
URL=[MeasureLocationIP]
StringIndex=5

[MeasureAdapter]
Measure=Plugin
Plugin=SysInfo
SysInfoType=ADAPTER_DESCRIPTION
SysInfoData=Best
DynamicVariables=1
IfMatch=GOOSEVPN
IfMatchAction=[!SetVariable VPNOn "1"][!EnableMeasure "MeasureCurrentLatitude"][!EnableMeasure "MeasureCurrentLongitude"]
IfNotMatchAction=[!SetVariable VPNOn "0"][!EnableMeasure "MeasureCurrentLatitude"][!EnableMeasure "MeasureCurrentLongitude"]
Disabled=1

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

[MeasureCurrentLongitude]
Measure=Calc
Formula=(1 - #VPNOn#) * [MeasureLongitude] + (#VPNOn#  * #Longitude# )
DynamicVariables=1
FinishAction=[!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"]
Disabled=1