It is currently March 29th, 2024, 5:22 am

Parsed string from weather.com

Get help with creating, editing & fixing problems with skins
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5384
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Parsed string from weather.com

Post by eclectic-tech »

Mor3bane wrote:...
Seeing no reason to create a shorter version, since I continually add features to my weather widgets nb- the timestamp im working on now. I just do not need the date or the region code. :)
Find the webparser child measure in your code that has StringIndex=15.

Add the RegExpSubstitute=1 and Substitution= code below to that measure.

Code: Select all

RegExpSubstitute=1
Substitute="^.*\s(.*)\s(.*)\s.*$":"\1 \2"
It will return just the 'HH:MM PM' from the indexed string '02/01/2018 HH:MM PM EST'.

EDIT ... Added explanation

Substition functions:
^ means begin at the start of the string
.*\s means capture nothing until it finds white space
(.*)\s means capture everything until it finds white space (used twice to capture time, and am/pm)
.*$ means capture nothing to the end of the string

\1 means display the first capture
\2 means display the second capture

Hope this helps! :welcome:
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: Parsed string from weather.com

Post by Mor3bane »

eclectic-tech wrote:Find the webparser child measure in your code that has StringIndex=15.

Add the RegExpSubstitute=1 and Substitution= code below to that measure.

Code: Select all

RegExpSubstitute=1
Substitute="^.*\s(.*)\s(.*)\s.*$":"\1 \2"
It will return just the 'HH:MM PM' from the indexed string '02/01/2018 HH:MM PM EST'.

EDIT ... Added explanation

Substition functions:
^ means begin at the start of the string
.*\s means capture nothing until it finds white space
(.*)\s means capture everything until it finds white space (used twice to capture time, and am/pm)
.*$ means capture nothing to the end of the string

\1 means display the first capture
\2 means display the second capture

Hope this helps! :welcome:
WOW! That was very helpful - thank you so much eclectic-tech for the explanations!! :17nodding
Edit: copy/pasted those awesome explainations for later 8-)
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Parsed string from weather.com

Post by balala »

Mor3bane wrote:

Code: Select all

[MeasureCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateDivider=80
Url=http://wxdata.weather.com/wxdata/weather/local/#Location#?cc=*&unit=f&dayf=1
RegExp="(?siU).*<locale>(.*)</locale>.*<ut>(.*)</ut>.*<ud>(.*)</ud>.*<us>(.*)</us>.*<up>(.*)</up>.*<ur>(.*)</ur>.*<loc id="(.*)">.*<dnam>(.*)</dnam>.*<tm>(.*)</tm>.*<lat>(.*)</lat>.*<lon>(.*)</lon>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<zone>(.*)</zone>.*<cc>.*<lsup>(.*)</lsup>.*<obst>(.*)</obst>.*<tmp>(.*)</tmp>.*<flik>(.*)</flik>.*<t>(.*)</t>.*<icon>(.*)</icon>.*<bar>.*<r>(.*)</r>.*<d>(.*)</d>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<vis>(.*)</vis>.*<uv>.*<i>(.*)</i>.*<t>(.*)</t>.*<dewp>(.*)</dewp>.*<moon>.*<icon>(.*)</icon>.*<t>(.*)</t>.*<ppcp>(.*)</ppcp>.*"
Beside eclectic-tech's very good reply (as usual), I'd add just three minor comments about the posted code. These details have no influence on how the measure is working, just seeing it, I had to tell that:
  • After all our discussion about the nature of the WebParser measures, if you keep it as a plugin measure, don't use the whole path, in the Plugin option. Replace the Plugin=Plugins\WebParser.dll option with Plugin=WebParser, which is perfectly enough.
  • Even if it's working, the unit=f, used in the URL, is wrong, because the unit should be either i (meaning imperial - temperatures in Fahrenheit degrees), or m (metric - temperatures in Celsius degrees) (yes, I know that beside the unit of the temperatures, other units are also different). The reason why it works even with unit=f is that if nor i and nor m is used, the default value is used, which is i. So, practically you get the temperatures in Celsius for unit=m and in Fahrenheit for any other unit (i, or anything else). See the discussion starting from this: https://forum.rainmeter.net/viewtopic.php?p=143874#p143874
  • The quotation marks around the value of the RegExp option are not needed. Remove them. Details here: https://forum.rainmeter.net/viewtopic.php?p=137628#p137628
User avatar
Mor3bane
Posts: 943
Joined: May 7th, 2016, 7:32 am

Re: Parsed string from weather.com

Post by Mor3bane »

balala wrote:Beside eclectic-tech's very good reply (as usual), I'd add just three minor comments about the posted code. These details have no influence on how the measure is working, just seeing it, I had to tell that:
  • After all our discussion about the nature of the WebParser measures, if you keep it as a plugin measure, don't use the whole path, in the Plugin option. Replace the Plugin=Plugins\WebParser.dll option with Plugin=WebParser, which is perfectly enough.
  • Even if it's working, the unit=f, used in the URL, is wrong, because the unit should be either i (meaning imperial - temperatures in Fahrenheit degrees), or m (metric - temperatures in Celsius degrees) (yes, I know that beside the unit of the temperatures, other units are also different). The reason why it works even with unit=f is that if nor i and nor m is used, the default value is used, which is i. So, practically you get the temperatures in Celsius for unit=m and in Fahrenheit for any other unit (i, or anything else). See the discussion starting from this: https://forum.rainmeter.net/viewtopic.php?p=143874#p143874
  • The quotation marks around the value of the RegExp option are not needed. Remove them. Details here: https://forum.rainmeter.net/viewtopic.php?p=137628#p137628
Noted. I will amend as per your advice. :)

EDIT: TBH that regexp was borrowed from some very old code. Thanks for showing me how to bring it up to the times.
My DevArt Gallery

There are many ways to be different - there is only one way to be yourself - be amazing at it

The law of averages says what it means; even if you get everything right, you will get something wrong. Therefore; self managing error trapping initiates another set of averages - amongst the errors, some of them will not be errors, instead those instances will appear to be "luck". One cannot complain of the 'appearance' of 'infinite regress of causation', even if it does not have a predictable pattern, only that it requires luck to achieve.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Parsed string from weather.com

Post by balala »

Mor3bane wrote:EDIT: TBH that regexp was borrowed from some very old code. Thanks for showing me how to bring it up to the times.
Your initial RegExp definitely works, there are no problems with it. What have I said, are just some details. However, I'm glad if I have drawn your attention to those details.