I've run into a problem while parsing from weather.codes.
The way the data shows makes it tricky to parse the correct weather code as they show:
[Weather Code]:[City, Country]
[CAXX0485]:[Surrey, Canada]
WebParser doesn't parse the code before the matching text and catching the first instance of code from
the search does not work because there are cities with the same name but from different countries.
I decided to try a workaround but unsure why it doesn't seem to work.
Basically, I am using one measure parsing all the "City, Country"s from the 2nd column
and using another measure to parse the weather codes, hoping to find a row that matches the exact "City, Country", and applying that row number to the "StringIndex" of a measure to output the correct weather code.
Code: Select all
[Rainmeter]
Author=Ekojain
Update=1000
[Metadata]
Version=1.0
[Variables]
City=Kyoto
Country=Japan
Location=
NameString=
;MEASURE (As the "Weather Codes" website has weather code first and city, country after,
;the two measures will parse the first 4 "City, Country"s and the first 4 Weather codes
[MeasureWeatherName]
Measure=Plugin
Plugin=WebParser
URL=https://weather.codes/search/?q=#City#
RegExp=(?siU)<dd>(.*)</dd>.*<dd>(.*)</dd>.*<dd>(.*)</dd>.*<dd>(.*)</dd>.*
UpdateRate=-1
FinishAction=
DynamicVariables=1
[MeasureWeatherCode]
Measure=Plugin
Plugin=WebParser
URL=https://weather.codes/search/?q=#City#
RegExp=(?siU)<dt>(.*)</dt>.*<dt>(.*)</dt>.*<dt>(.*)</dt>.*<dt>(.*)</dt>.*
UpdateRate=-1
FinishAction=
DynamicVariables=1
;Depending on the index line that the correct City, Country text matches,
;the correct index line will be named as "#NameString#" for [MeasureCode] to output.
[MeasureName1]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWeatherName]
StringIndex=1
[CalcName1]
Measure=Calc
Formula=[MeasureName1]
IfMatch=#City#, #Country#:True
IfMatchAction=[!WriteKeyValue "MeasureCode" "StringIndex" "1" "Weather.ini"]
[MeasureName2]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWeatherName]
StringIndex=2
[CalcName2]
Measure=Calc
Formula=[MeasureName2]
IfMatch=#City#, #Country#:True
IfMatchAction=[!WriteKeyValue "MeasureCode" "StringIndex" "2" "Weather.ini"]
[MeasureName3]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWeatherName]
StringIndex=3
[CalcName3]
Measure=Calc
Formula=[MeasureName3]
IfMatch=#City#, #Country#:True
IfMatchAction=[!WriteKeyValue "MeasureCode" "StringIndex" "3" "Weather.ini"]
[MeasureName4]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWeatherName]
StringIndex=4
[CalcName4]
Measure=Calc
Formula=[MeasureName4]
IfMatch=#City#, #Country#:True
IfMatchAction=[!WriteKeyValue "MeasureCode" "StringIndex" "4" "Weather.ini"]
;This reads the output from [MeasureWeatherCode] and applies the right Stringindex to display.
[MeasureCode]
Measure=Plugin
Plugin=WebParser
URL=[MeasureWeatherCode]
StringIndex=#NameString#
UpdateRate=-1
DynamicVariables=1
;This is just the trigger for the input.
[MeterBACK]
Meter=Image
X=0
Y=0
W=200
H=100
SolidColor=FFFFFF
[CountryBack]
Meter=String
X=10
Y=10
Text=Country
FontSize=10
FontColor=000000
FontFace=Myriad Pro
AntiAlias=1
[CoutryBacktext]
Meter=String
Y=r
X=100r
FontSize=10
FontColor=000000
FontFace=Myriad Pro
Text=#Country#
LeftMouseUpAction=[!CommandMeasure "INPUT1 ExecuteBatch 1-2"]
AntiAlias=1
[CityBack]
Meter=String
X=10
Y=30r
Text=City
FontSize=10
FontColor=000000
FontFace=Myriad Pro
AntiAlias=1
[CityBacktext]
Meter=String
Y=r
X=100r
FontSize=10
FontColor=000000
FontFace=Myriad Pro
Text=#City#
LeftMouseUpAction=[!CommandMeasure "INPUT2 ExecuteBatch 1-2"]
AntiAlias=1
[CodeBack]
Meter=String
X=10
Y=30r
Text=Location
FontSize=10
FontColor=000000
FontFace=Myriad Pro
AntiAlias=1
[CodeBacktext]
Meter=String
Y=r
X=100r
FontSize=10
FontColor=000000
FontFace=Myriad Pro
Text=#Location#
AntiAlias=1
;This input writes the output from [MeasureCode], which is the Weather Code to the Variables file.
[INPUT1]
Measure=Plugin
Plugin=InputText.dll
X=80
Y=10
W=100
H=16
SolidColor=100,100,100,255
FontColor=0,0,0,255
FontSize=10
FontFace=Arial
StringAlign=Right
FocusDismiss=1
Command1=[!WriteKeyValue "Variables" "Country" "$UserInput$" "Weather.ini"]
Command2=[!WriteKeyValue "Variables" "Location" "[MeasureCode]" "Weather.ini"][!Refresh]
[INPUT2]
Measure=Plugin
Plugin=InputText.dll
X=80
Y=40
W=100
H=16
SolidColor=100,100,100,255
FontColor=0,0,0,255
FontSize=10
FontFace=Arial
StringAlign=Right
FocusDismiss=1
Command1=[!WriteKeyValue "Variables" "City" "$UserInput$" "Weather.ini"]
Command2=[!WriteKeyValue "Variables" "Location" "[MeasureCode]" "Weather.ini"][!Refresh]