It is currently February 20th, 2020, 6:20 pm

⭐ weather.com - Some Tools for Parsing

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
jsmorley
Developer
Posts: 20269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

⭐ weather.com - Some Tools for Parsing

Post by jsmorley »

Ok, here is something I think might help...

What I have done is create several @Include files that basically have all the measures you need to get all the weather information for your skin.

WeatherComVariables.inc
This is where you set your Location Code and Language variables.
This is the only one you should really edit.

WeatherComRegExp.inc
This is used to parse the weather.com website with Regular Expression.
Seriously, don't edit this unless you know what you are doing.

See the information at the bottom of this post for details on the measures returned by each of the following @Include files.

WeatherComCurrent.inc
Measures for all the "current" weather information.
Also has The Location Name, Observation Time, Temperature Unit of Measure, Today's High and Low Temperatures and Sunrise / Sunset.
WeatherComForecast.inc
Measures for weather forecasts for today, and the following 7 days.
At some point in the afternoon, this will change from "Today" to "Tonight".
WeatherCom36Hours.inc
Measures for the forecasts on the 5 "cards" that display the day/night weather for the next "36 hours".
Using this requires that you also load WeatherComCurrent.inc.
WeatherComHourly.inc
Measures for weather forecasts, hourly, for the next 12 hours.
This will start at the most recent observation time in the current hour, and then on the hour for the next 11 hours.

Always @Include[N] WeatherComVariables.inc and WeatherComRegExp.inc, then just use any or all of the others you need for your skin design.

Most skins will want to use at least WeatherComCurrent.inc and probably WeatherComForecast.inc.

Then you can just concentrate on the Meters in your skin. All the measures you will need are already there! Just create the meters, and use the MeasureName= options you can easily get by looking at About/Skins to see what the measure names are that are populated. I tried to make the measure names as descriptive as possible, and if you look in the include files, I have done as much commenting as I can.

If you want to "overload" an included measure, for instance to use Substitute or put an IfCondition or IfMatch on the measure, just create a copy of the measure as a Measure=String or Measure=Calc in the skin, and dynamically use the value of the original measure as a [SectionVariable].

I DON'T recommend altering the @Include files, as that just reduces their usefulness as something you can just plug into another new skin, and makes is very difficult indeed for you if I update them.

Here is the entire thing as an example you can examine and use:


WeatherTemplate_Jan 27, 2020.rmskin

1.png


So that should make the "skin" part of the equation a lot easier...

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
ContextTitle=Edit Weather Variables
ContextAction=["#@#\WeatherComVariables.inc"]

[Variables]
@Include1=#@#WeatherComVariables.inc
@Include2=#@#WeatherComRegExp.inc
@Include3=#@#WeatherComCurrent.inc
;@Include4=#@#WeatherComForecast.inc
;@Include5=#@#WeatherCom36Hours.inc
;@Include6=#@#WeatherComHourly.inc

[MeasureGotTheData]
Measure=String
String=[@CurrentLocationName]
DynamicVariables=1
IfMatch=^$
IfNotMatchAction=[!HideMeter MeterReticulating][!ShowMeterGroup AllMeters][!Update]

; Overrides a template measure

[NewCurrentTemperatureLow]
Measure=String
Group=Weather
String=[@CurrentTemperatureLow]
DynamicVariables=1
; Note that after some point in the afternoon, there will 
; be NO Low Temperature returned. The High Temperature
; returned will then be the "low" from the current time until
; midnight of the same day.
; This can be tested with: 
IfMatch=^$
IfMatchAction=[!SetOption MeterTodayHighLow Text "Low Tonight %1%2"]
IfNotMatchAction=[!SetOption MeterTodayHighLow Text "%1%2 | %3%4"]

; Meters

[MeterReticulating]
Meter=String
X=300
Y=45
StringAlign=Center
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
Padding=5,5,5,5
AntiAlias=1
Text=Reticulating Splines

[MeterCurrentTemperature]
Meter=String
Group=AllMeters
MeasureName=@CurrentTemperature
MeasureName2=@CurrentTemperatureSymbol
MeasureName3=@CurrentTemperatureUnit
X=300
Y=0
StringAlign=Right
FontSize=40
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Hidden=1
Text=%1%2%3

[MeterCurrentConditions]
Meter=String
Group=AllMeters
MeasureName=@CurrentConditions
X=300
Y=-8R
StringAlign=Right
FontSize=15
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Hidden=1

[MeterTodayHighLow]
Meter=String
Group=AllMeters
MeasureName=@CurrentTemperatureHigh
MeasureName2=@CurrentTemperatureHighSymbol
MeasureName3=@CurrentTemperatureLow
MeasureName4=@CurrentTemperatureLowSymbol
X=300
Y=2R
StringAlign=Right
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1
Hidden=1

[MeterCurrentIcon]
Meter=Image
Group=AllMeters
MeasureName=@CurrentIcon
ImagePath=#@#TWCIcons\
X=320
Y=-14
Hidden=1




WeatherComCurrent.inc

This @Include file is used to return and use the information for the weather as it is currently, as of the most recent observation.

This is not an exhaustive list, as there are measures returned that provide both the text labels and in some cases the unit symbols.
Use About / Skins to see all of the measures that are returned when this @Include file is used.

@MeasureName : Type of Information

@CurrentLocationName : Location Name
@CurrentTemperatureUnit : F or C Temperature Unit
@CurrentObservationTime : Observation Time and Timezone Abbreviation
@CurrentIcon : Current Icon Number
@CurrentTemperature : Current Temperature
@CurrentConditions : Current Conditions Text
@CurrentFeelsLike : Current Feels Like Temperature
@CurrentTemperatureHigh : Today's Projected High Temperature
@CurrentTemperatureLow : Today's / Tonight's Projected Low Temperature
Note that after some point in the afternoon, there will be NO Low Temperature returned. The High Temperature
returned will then be the "low" from the current time until midnight of the same day.

@CurrentUVIndexNumberValue : Current UV Index Number Value
@CurrentUVIndexTextValue : Current UV Index Text Value
@CurrentWindDirection : Current Wind Direction
@CurrentWind : Current Wind Speed and Unit of Speed
@CurrentHumidity : Current Humidity Percent
@CurrentDewPoint : Current Dew Point Temperature
@CurrentPressure : Current Barometric Pressure and Unit of Pressure
@CurrentPressureChange : Current Barometric Pressure Direction of Change
@CurrentVisibilityDistance : Current Visibility Distance and Unit of Distance
@CurrentSunrise : Today's Sunrise Time
@CurrentSunset : Today's Sunset Time

Example:

Code: Select all

[Variables]
@Include1=#@#WeatherComVariables.inc
@Include2=#@#WeatherComCurrent.inc

[MeterConditions]
Meter=String
MeasureName=@CurrentConditions

WeatherComForecast.inc

This @Include file is used to return and use the forecasted weather information, for today and the following 7 days.

This is not an exhaustive list, as there are measures returned that provide both the text labels and in some cases the unit symbols.
Use About / Skins to see all of the measures that are returned when this @Include file is used.

@MeasureName : Type of Information

@ForecastDay1Name : This will always be either "Today", or at some point in the afternoon "Tonight"
@ForecastDay1Icon : Forecasted Day 1 Icon Number
@ForecastDay1Date : Date for Day 1 in the form MON dd
@ForecastDay1Conditions : Forecasted Day 1 Conditions Text
Note that there is no forecasted High or Low for Today. Use the information from:
@CurrentTemperatureHigh : Today's Projected High Temperature
@CurrentTemperatureLow : Today's / Tonight's Projected Low Temperature

@ForecastDay1Precipitation : Forecasted Day 1 Percent Precipitation Possibility
@ForeCastDay1Details : A text string generally describing the Day 1 Forecasted Conditions, Highs, Winds and Precipitation

@ForecastDay2Name : Abbreviated Day of the Week Name
@ForecastDay2Icon : Forecasted Day 2 Icon Number
@ForecastDay2Date : Date for Day 2 in the form MON dd
@ForecastDay2Conditions : Forecasted Day 2 Conditions Text
@ForecastDay2High : Forecasted Day 2 High Temperature
@ForecastDay2Low : Forecasted Day 2 Low Temperature
@ForecastDay2Precipitation : Forecasted Day 2 Percent Precipitation Possibility
@ForeCastDay2Details : A text string generally describing the Day 2 Forecasted Conditions, Highs, Winds and Precipitation

... This will follow the same pattern for Day 3 through Day 8

@ForecastDay8Name : Abbreviated Day of the Week Name
@ForecastDay8Icon : Forecasted Day 8 Icon Number
@ForecastDay8Date : Date for Day 8 in the form MON dd
@ForecastDay8Conditions : Forceasted Day 8 Conditions Text
@ForecastDay8High : Forecasted Day 8 High Temperature
@ForecastDay8Low : Forecasted Day 8 Low Temperature
@ForecastDay8Precipitation : Forecasted Day 8 Percent Precipitation Possibility
@ForeCastDay8Details : A text string generally describing the Day 8 Forecasted Conditions, Highs, Winds and Precipitation


WeatherCom36Hours.inc

This @Include file is used to return and use the forecasted weather information, using 5 "Cards" for the next 36 hours.
Early in the day the Card 1 will start with "Today", then follow with "Tonight"
At some point in the afternoon, Card 1 will start with "Tonight", then the "Day of the Week" for the following day.
The following Cards will be in the form "Day of the Week", then "Day of the Week Night".

This is not an exhaustive list, as there are measures returned that provide both the text labels and in some cases the unit symbols.
Use About / Skins to see all of the measures that are returned when this @Include file is used.

@MeasureName : Type of Information

@Card1Day : This will always be either "Today", or at some point in the afternoon "Tonight"
@Card1Conditions : Card 1 Forecasted Conditions Text
@Card1Icon : Card 1 Forecasted Icon Number
@Card1HighLowText : This will be "High" early in the day, and "Low" after some point in the afternoon
@Card1HighLowValue : This will be the Card 1 Forecasted High Temperature early in the day, and the Low Temperature after some point in the afternoon
@Card1Precipitation : Card 1 Percent Precipitation Possibility
@Card1Details : A text string generally describing the Card 1 Forecasted Conditions, Highs, Winds and Precipitation

@Card2Day : This will always be either "Tonight" or the day of the week for the following day
@Card2Conditions : Card 2 Forecasted Conditions Text
@Card2Icon : Card 2 Forecasted Icon Number
@Card2HighLowText : This will be "High" or "Low" depending on the Card reflecting "day" or "night"
@Card2HighLowValue : This will be the Card 2 Forecasted High Temperature or Low Temperature depending on the Card reflecting "day" or "night"
@Card2Precipitation : Card 1 Percent Precipitation Possibility
@Card2Details : A text string generally describing the Card 2 Forecasted Conditions, Highs, Winds and Precipitation

@Card3Day : This will be either "Day of the Week", or "Day of the Week Night"
@Card3Conditions : Card 3 Forecasted Conditions Text
@Card3Icon : Card 3 Forecasted Icon Number
@Card3HighLowText : This will be "High" or "Low" depending on the Card reflecting "day" or "night"
@Card3HighLowValue : This will be the Card 3 Forecasted High Temperature or Low Temperature depending on the Card reflecting "day" or "night"
@Card3Precipitation : Card 3 Percent Precipitation Possibility
@Card3Details : A text string generally describing the Card 3 Forecasted Conditions, Highs, Winds and Precipitation

@Card4Day : This will be either "Day of the Week", or "Day of the Week Night"
@Card4Conditions : Card 4 Forecasted Conditions Text
@Card4Icon : Card 4 Forecasted Icon Number
@Card4HighLowText : This will be "High" or "Low" depending on the Card reflecting "day" or "night"
@Card4HighLowValue : This will be the Card 4 Forecasted High Temperature or Low Temperature depending on the Card reflecting "day" or "night"
@Card4Precipitation : Card 4 Percent Precipitation Possibility
@Card4Details : A text string generally describing the Card 4 Forecasted Conditions, Highs, Winds and Precipitation

@Card5Day : This will be either "Day of the Week", or "Day of the Week Night"
@Card5Conditions : Card 5 Forecasted Conditions Text
@Card5Icon : Card 5 Forecasted Icon Number
@Card5HighLowText : This will be "High" or "Low" depending on the Card reflecting "day" or "night"
@Card5HighLowValue : This will be the Card 5 Forecasted High Temperature or Low Temperature depending on the Card reflecting "day" or "night"
@Card5Precipitation : Card 5 Percent Precipitation Possibility
@Card5Details : A text string generally describing the Card 5 Forecasted Conditions, Highs, Winds and Precipitation


WeatherComHourly.inc

This @Include file is used to return and use the current and forecasted weather information hourly, for the next 12 hours.
This will start with the weather as it is currently, as of the most recent observation, then forecasted for the top of each hour.

This is not an exhaustive list, as there are measures returned that provide both the text labels and in some cases the unit symbols.
Use About / Skins to see all of the measures that are returned when this @Include file is used.

@MeasureName : Type of Information

@Hourly1Time : Hour 1 Time
@Hourly1Icon : Hour 1 Icon Number
@Hourly1Day : Hour 1 Day of the Week
@Hourly1Conditions : Hour 1 Conditions Text
@Hourly1Temperature : Hour 1 Temperature
@Hourly1Precipitation : Hour 1 Percent Precipitation Possibility

@Hourly2Time : Hour 2 Time
@Hourly2Icon : Hour 2 Icon Number
@Hourly2Day : Hour 2 Day of the Week
@Hourly2Conditions : Hour 2 Conditions Text
@Hourly2Temperature : Hour 2 Temperature
@Hourly2Precipitation : Hour 2 Percent Precipitation Possibility

... This will follow the same pattern for Hour 3 through Hour 12

@Hourly12Time : Hour 12 Time
@Hourly12Icon : Hour 12 Icon Number
@Hourly12Day : Hour 12 Day of the Week
@Hourly12Conditions : Hour 12 Conditions Text
@Hourly12Temperature : Hour 12 Temperature
@Hourly12Precipitation : Hour 12 Percent Precipitation Possibility


You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 20269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Some help with parsing weather.com

Post by jsmorley »

Updated the RegExp to include "Dew Point" values.
SCR
Posts: 32
Joined: April 15th, 2015, 11:13 pm

Re: ⭐ Some help with parsing weather.com

Post by SCR »

Wow, this really helps a lot.

Thank you
User avatar
SilverAzide
Posts: 690
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ Some help with parsing weather.com

Post by SilverAzide »

jsmorley wrote:
January 19th, 2020, 1:36 am
Feel free to ask questions...
I found a few typos in the WeatherMeasures.inc file. ("Visibility" and I think the final Measure36HoursDetailsParent is referencing the wrong super-parent, though I could be wrong as both appear to work... just makes more sense if it uses the same parent as all the card measures.)

I also added additional grouping so that measures you might not need for a particular skin can be turned off in chunks related to the parents.

Groups are:
Weather = everything is in this group
WeatherCurrent = the current conditions measures
WeatherEightDay = the eight-day forecast measures
WeatherHourByHour = the hour-by-hour measures (there are no children of this parent (yet?))
WeatherNext36Hours = the 36-hour forecast card measures (this needs WeatherCurrent, so you can't turn off that group)

I think you can control the groups like this:

Code: Select all

[Rainmeter]
OnRefreshAction=[!DisableMeasureGroup WeatherEightDay][!DisableMeasureGroup WeatherHourByHour]
I tried to step as lightly as possible so diffing is easy. Humbly submitted for your consideration:
You do not have the required permissions to view the files attached to this post.
DeviantArt Gadgets More...
User avatar
jsmorley
Developer
Posts: 20269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Some help with parsing weather.com

Post by jsmorley »

SilverAzide wrote:
January 20th, 2020, 1:21 am
I found a few typos in the WeatherMeasures.inc file. ("Visibility" and I think the final Measure36HoursDetailsParent is referencing the wrong super-parent, though I could be wrong as both appear to work... just makes more sense if it uses the same parent as all the card measures.)

I also added additional grouping so that measures you might not need for a particular skin can be turned off in chunks related to the parents.

Groups are:
Weather = everything is in this group
WeatherCurrent = the current conditions measures
WeatherEightDay = the eight-day forecast measures
WeatherHourByHour = the hour-by-hour measures (there are no children of this parent (yet?))
WeatherNext36Hours = the 36-hour forecast card measures (this needs WeatherCurrent, so you can't turn off that group)

I think you can control the groups like this:

Code: Select all

[Rainmeter]
OnRefreshAction=[!DisableMeasureGroup WeatherEightDay][!DisableMeasureGroup WeatherHourByHour]
I tried to step as lightly as possible so diffing is easy. Humbly submitted for your consideration:
I like the grouping. I'm not sure it buys you much to turn off child measures, as they don't really take any resources anyway, but it's worth having.
Yeah, I just have not done anything yet with HourByHour or Alerts. HourByHour is just so overkill on the desktop for my tastes, and Alerts are really a mess to deal with. I'll get around to them at some point. We should probably also deal with the "moon" stuff someday, although that is such a "huh? who cares?" for me.

I have broken this up into separate .inc files by "super parent", so rather than disabling a group and having all of them still show up in About/Skins but just greyed out, you can simply not @Include something you don't use. The entire combined @Include created 172 measures, and you might use like 10 of them for a simple skin. This is only going to get worse as we deal with HourByHour, Alerts, and MoonPhase stuff.

So now we have:

WeatherComCurrent.inc
WeatherCom36Hours.inc
WeatherComForecast.inc

What I did with WeatherCom36Hours.inc is to include the "current" super parent as a part of it, but commented it out. You would only need to un-comment and use that measure if you are not including WeatherComCurrent.inc, which is unlikely.

That brings WeatherComCurrent.inc, which for many people is all they need for a simple skin, down to 36 measures instead of 172.
User avatar
SilverAzide
Posts: 690
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ Some help with parsing weather.com

Post by SilverAzide »

Excellent! Cuts down the startup time of the skin by more than half, and reduces the CPU as well. :thumbup:
DeviantArt Gadgets More...
User avatar
CyberTheWorm
Posts: 682
Joined: August 22nd, 2016, 11:32 pm
Location: Surrey, B.C., Canada

Re: ⭐ Some help with parsing weather.com

Post by CyberTheWorm »

Thanks, this really helps
The only source of knowledge is experience. Albert Einstein
Deviant Art Page
xenium
Posts: 481
Joined: January 4th, 2018, 9:52 pm

Re: ⭐ Some help with parsing weather.com

Post by xenium »

jsmorley wrote:
January 20th, 2020, 1:52 am
Yeah, I just have not done anything yet with HourByHour or Alerts. HourByHour is just so overkill on the desktop for my tastes, and Alerts are really a mess to deal with. I'll get around to them at some point.
My advice:
If you do not want headaches, avoid the Code Alerts section.
It is difficult to implement by users, special measures are required with certain options each for alerts to work and no errors in the Log.
Over 80% of the time allocated to the W10WEnterp skin I spent it trying to make the alerts work.
And one more thing.
Last year TWC changed the source code 3 times and all 3 targeted the alerts section (see Updates on page W10WEnterpr)
So ...
You can also avoid the Hours section, a few users will want to display on the screen every hour. This information is covered by the real-time details for Today / Tonight, which are updated every 10 minutes.
Most users want the current weather + 5 to 7 days forecast.
Some weather parameters I did not enter in the code: besides dewpoint and humidity + wind for the forecast days.
The wind appears in the tooltip details for each day.
The rest of the code is easy to use
iron2000
Posts: 11
Joined: June 6th, 2011, 3:47 am

Re: ⭐ Some help with parsing weather.com

Post by iron2000 »

Thanks for making this Xenium and jsmorley :thumbup:

Was thinking about translations when I read in the other thread that the language code does it.
Found a list here, the "Accept-language string" column:
https://www.w3.org/International/ms-lang.html

I didn't test them all though, Chinese and Japanese works.

Now have to figure out how to weave it into my skins.
This is really great help, thanks again guys.
User avatar
jsmorley
Developer
Posts: 20269
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Some help with parsing weather.com

Post by jsmorley »

xenium wrote:
January 20th, 2020, 10:24 am
My advice:
If you do not want headaches, avoid the Code Alerts section.
It is difficult to implement by users, special measures are required with certain options each for alerts to work and no errors in the Log.
Over 80% of the time allocated to the W10WEnterp skin I spent it trying to make the alerts work.
And one more thing.
Last year TWC changed the source code 3 times and all 3 targeted the alerts section (see Updates on page W10WEnterpr)
So ...
You can also avoid the Hours section, a few users will want to display on the screen every hour. This information is covered by the real-time details for Today / Tonight, which are updated every 10 minutes.
Most users want the current weather + 5 to 7 days forecast.
Some weather parameters I did not enter in the code: besides dewpoint and humidity + wind for the forecast days.
The wind appears in the tooltip details for each day.
The rest of the code is easy to use
I agree entirely with everything you just said.

I think with Alerts, my goal is going to be just to detect that there ARE one or more "high priority" alerts, and just allow the skin to indicate that. Then have a link that just goes to the website. I think parsing and displaying the number and contents of alerts is a bridge too far.