It is currently April 20th, 2024, 11:39 am

Regexp help: Measure only capturing first Match

Get help with creating, editing & fixing problems with skins
acercanto
Posts: 4
Joined: February 21st, 2019, 5:57 pm

Regexp help: Measure only capturing first Match

Post by acercanto »

Hello,
I am attempting to recreate the NOAA forecast graph as a skin, and the first of many hurdles I foresee is capturing all the numbers so I can display them eventually. I found that NOAA has an XML version of the page, which is marginally easier to parse.
I started with temperature, because it seemed the easiest to parse.

Code: Select all

[MeasureGrabSite]
Measure=WebParser
URL=#XMLWeatherPage#
RegExp=(?s)(<data>.+<\/data>)
UpdateRate=30
;==================Grabs everything inside the "data" tags into StringIndex 1
;----------------------------------------------------------

[MeasureFuzzyLocation]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<area-description>(.+)<\/area-description>
StringIndex=1
StringIndex2=1
;==================Pulls the Area Description from StringIndex 1 of the Master Grab
;----------------------------------------------------------

[MeasureTemp]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<temperature type="hourly" time-layout="k-p1h-n1-0">(<value>\d{1,3}<\/value>.+)<\/temperature>
StringIndex=1
StringIndex2=1
;==================Pulls the temp data (plus the <value> tags) from StringIndex 1 of the Master Grab

[MeasureTempDigits]
Measure=WebParser
URL=[MeasureTemp]
RegExp=(?s)(\d{1,3})
StringIndex=1
StringIndex2=1
;==================Secondary regex to strip the <value> tags off the temp
Fullscreen capture 2212019 134809.jpg
The MeasureTempDigits Regexp works when I plug it into https://regex101.com/r/cO8lqs/7997, but for some reason, the Measure only records the first entry. I've hunted around, and seen a lot of examples where they use multiple Measures to grab news headlines and stuff, but I just need the numbers, and it seems a bit excessive to have 48 or 72 Measures (the next 2 or 3 days) just to grab 2 digits.
I have other issues, like that it takes a full minute and 9 seconds for the skin to display the data that I have managed to get into a meter.
I have been using the RainRegExp tool quite a bit, as well as Regex101.com. There a whole slew of issues I can see ahead of me, so if any of you sages know of an easier way to do this, I'm all ears. There's no way to just render a snippet of html, is there?

Thanks,
Acercanto
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Regexp help: Measure only capturing first Match

Post by balala »

acercanto wrote: February 21st, 2019, 6:59 pm I've hunted around, and seen a lot of examples where they use multiple Measures to grab news headlines and stuff, but I just need the numbers, and it seems a bit excessive to have 48 or 72 Measures (the next 2 or 3 days) just to grab 2 digits.
There is no easier way. Rainmeter is not a programming language and that's why you have to create so many measures as many temperatures you'd like to get. There is no other simple way to manage them. Eventually just using a .lua script (lua being a programming language) and ask it to return all those temperatures. But this isn't something easy. Especially not for a beginner.
But with 48 or 72 measures you won't grab just two digits, but 48 or 72 times two digits.
I recommend to keep working and add manually all the 48 or 72 measures (or as many as needed - up to 99). Finally you have to do this just once.
acercanto
Posts: 4
Joined: February 21st, 2019, 5:57 pm

Re: Regexp help: Measure only capturing first Match

Post by acercanto »

Thanks for the reply. I was afraid that there was no easy way, but it's good to have confirmation. Any idea why it's taking so long to update the Measures with the data from the page? I don't feel like the few little Regexs should take over a minute to parse.. I tried using the FinishAction with an !UpdateMeter bang, but that didn't seem to help any.

Is there any way to have Rainmeter render a scrap of html?

Ever optimistic,
Acercanto
User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Regexp help: Measure only capturing first Match

Post by balala »

acercanto wrote: February 21st, 2019, 9:09 pm Any idea why it's taking so long to update the Measures with the data from the page?
No, no idea so, but a code would be useful, to can test it and see what's going on. Please post it.
acercanto
Posts: 4
Joined: February 21st, 2019, 5:57 pm

Re: Regexp help: Measure only capturing first Match

Post by acercanto »

Well I think I'm one step closer to cracking it. I used Substitute on the <value> tags to remove them and add a space.
Full (unfinished) skin is as follows

Code: Select all

[Metadata]
Author=Acercanto
Name=NOAA weather forecast graph
Information=A graphical recreation of the NOAA weather forecast graph.
Version=1
License=Creative Commons BY-NC-SA 3.0

[Rainmeter]
Update=60000
BackgroundMode=2
SolidColor=80,80,80,200
AccurateText=1
DynamicWindowSize=1

[Variables]
Latitude=37.1644
Longitude=-80.6154
XMLWeatherPage=https://forecast.weather.gov/MapClick.php?lat=#Latitude#&lon=#Longitude#&FcstType=digitalDWML

[FontStyle]
FontFace=Calibri UI
FontSize=12
FontColor=255,255,255,255
AntiAlias=1

;//////////////////////////
;|||| Data Chopping
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureGrabSite]
Measure=WebParser
URL=#XMLWeatherPage#
RegExp=(?s)(<data>.+<\/data>)
UpdateRate=30

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

[MeasureFuzzyLocation]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<area-description>(.+)<\/area-description>
StringIndex=1
StringIndex2=1

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

[MeasureTemp]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<temperature type="hourly" time-layout="k-p1h-n1-0">(<value>\d{1,3}<\/value>.+)<\/temperature>
StringIndex=1
StringIndex2=1

[MeasureTempDigit1]
Measure=WebParser
URL=[MeasureTemp]
;RegExp=(\d{1,3})
StringIndex=1
Substitute="<value>":"","</value>":" "

[MeasureTempDigit2]
Measure=WebParser
URL=[MeasureTemp]
RegExp=(\d{1,3})
StringIndex=1
StringIndex2=2

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

[MeasureWindChill]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<temperature type="wind chill".*?>(.+)<\/temperature>
StringIndex=1
StringIndex2=1

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

[MeasureTime]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)(?'time'\d\d:\d\d)(?=:\d\d-\d\d:\d\d<\/s.+)
StringIndex=1
StringIndex2=1


;RegExp="<temperature type="hourly" time-layout="k-p1h-n1-0">(.+)<\/temperature>"


;//////////////////////////
;|||| Meters for Display
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeterLocation]
Meter=String
MeasureName=MeasureFuzzyLocation
Text=Current location: %1
X=0
Y=0
MeterStyle=FontStyle
Antialias=1

[MeterTemp1]
Meter=String
MeasureName=MeasureTempDigit1
X=25
Y=25R
MeterStyle=FontStyle
Antialias=1

[MeterTemp2]
Meter=String
MeasureName=MeasureTempDigit2
X=25
Y=25R
MeterStyle=FontStyle
Antialias=1
acercanto
Posts: 4
Joined: February 21st, 2019, 5:57 pm

Re: Regexp help: Measure only capturing first Match

Post by acercanto »

Well, the more I get into this, the more I realize I'm asking way too much of Rainmeter. I was able to get the numbers separate, but I don't think there's a straightforward way to graph them.
Thanks for the help, @balala. :thumbup:
Here's the code I did manage to get sorted, in case anyone else wants to try their hand at something similar.

Acercanto

Code: Select all

[Metadata]
Author=Acercanto
Name=NOAA weather forecast graph
Information=A graphical recreation of the NOAA weather forecast graph.
Version=.0001
License=Creative Commons BY-NC-SA 3.0

[Rainmeter]
Update=60000
BackgroundMode=2
SolidColor=80,80,80,200
AccurateText=1
DynamicWindowSize=1

[Variables]
Latitude=37.1644
Longitude=-80.6154
XMLWeatherPage=https://forecast.weather.gov/MapClick.php?lat=#Latitude#&lon=#Longitude#&FcstType=digitalDWML

[FontStyle]
FontFace=Calibri UI
FontSize=12
FontColor=255,255,255,255
AntiAlias=1

;//////////////////////////
;|||| Data Grabbing
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureGrabSite]
Measure=WebParser
URL=#XMLWeatherPage#
RegExp=(?s)(<data>.+<\/data>)
UpdateRate=30

;//////////////////////////
;|||| Location
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureFuzzyLocation]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<area-description>(.+)<\/area-description>
StringIndex=1
StringIndex2=1

;//////////////////////////
;|||| Temperature
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureTemp]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<temperature type="hourly" time-layout="k-p1h-n1-0">(<value>\d{1,3}<\/value>.+)<\/temperature>
;RegExp="<temperature type="hourly" time-layout="k-p1h-n1-0">(.+)<\/temperature>"
StringIndex=1
StringIndex2=1

[MeasureTempDigits]
Measure=WebParser
URL=[MeasureTemp]
;RegExp=(\d{1,3})
StringIndex=1
Substitute="<value>":"","</value>":","

[MeasureTempMax]
Measure=Calc
Formula=Ceil(MeasureTempDigits)+5

;//////////////////////////
;|||| Wind Chill
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureWindChill]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)<temperature type="wind chill".*?>(.+)<\/temperature>
StringIndex=1
StringIndex2=1

[MeasureWindChillDigits]
Measure=WebParser
URL=[MeasureWindChill]
StringIndex=1
Substitute="<value>":"","</value>":","


;//////////////////////////
;|||| Time
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureTime]
Measure=WebParser
URL=[MeasureGrabSite]
RegExp=(?s)(?'time'\d\d:\d\d)(?=:\d\d-\d\d:\d\d<\/s.+)
StringIndex=1
StringIndex2=1
;WORK ON

;//////////////////////////
;|||| Wind
;\\\\\\\\\\\\\\\\\\\\\\\\\\

[MeasureWind]
Measure=WebParser
URL=[MeasureGrabSite]
Regexp=(?s)<wind-speed type="sustained" time-layout="k-p1h-n1-0">(<value>\d{1,3}<\/value>.+)<\/wind-speed>.*<cl
StringIndex=1
StringIndex2=1
Substitute="<value>":"","</value>":" "


;///////////////////////////////////////////////////////////////
;|||||||| METERS
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


[MeterLocation]
Meter=String
MeasureName=MeasureFuzzyLocation
Text=Current location: %1
X=0
Y=0
MeterStyle=FontStyle
Antialias=1

[MeterTemp1]
Meter=String
MeasureName=MeasureTempDigits
X=25
Y=25R
MeterStyle=FontStyle
FontSize=10
Antialias=1

[MeterWind]
Meter=Line
MeasureName=MeasureWind
LineColor=099,000,099,255
AutoScale=1
GraphStart=Left
X=10
Y=50R
W=100
H=50
MeterStyle=FontStyle
Antialias=1

User avatar
balala
Rainmeter Sage
Posts: 16148
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Regexp help: Measure only capturing first Match

Post by balala »

acercanto wrote: February 22nd, 2019, 3:09 am Here's the code I did manage to get sorted, in case anyone else wants to try their hand at something similar.
Update=60000? This is why you get the skin updated just after one minute.
I'd modify the Update to the default Update=1000. Don't worry, your computer won't be loaded too much, it'll work very good even with this Update, plus you'll get the skin updated right immediately after the WebParser measures get the data.