It is currently March 28th, 2024, 7:35 pm

⭐ Weather.com - Parsing the V3 JSON

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by Yincognito »

jsmorley wrote: June 16th, 2020, 10:24 pmPlease let me know if you spot 👀 anything wrong, that inc file is a 7,000+ line, 965 measures beast now, and goodness knows I could have botched something with the tons of copy/paste and search/replace I did, don't even get me started on the RegExp involved for each "day"

RegExp=(?siU)"getSunV3DailyForecastUrlConfig":.*"duration:15day;.*"dayOfWeek":\s*\[(?:".*",\s*){0}(".*").*"narrative":\s*\[(?:".*",\s*){0}(".*").*"qpf":\s*\[(?:.*,\s*){0}(.*),.*"qpfSnow":\s*\[(?:.*,\s*){0}(.*),.*"sunriseTimeLocal":\s*\[(?:".*",\s*){0}(".*").*"sunsetTimeLocal":\s*\[(?:".*",\s*){0}(".*").*"temperatureMax":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),.*"temperatureMin":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),.*"cloudCover":\s*\[(?:.*,\s*){0}(.*),\s*(.*)(?:,|\]).*"dayOrNight":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"daypartName":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"iconCode":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"narrative":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"precipChance":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"precipType":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"qpf":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"qpfSnow":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"relativeHumidity":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"snowRange":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"temperature":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"temperatureHeatIndex":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"temperatureWindChill":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"thunderCategory":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"thunderIndex":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"uvDescription":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"uvIndex":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"windDirection":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"windDirectionCardinal":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"windPhrase":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"windSpeed":\s*\[(?:null,\s*|.*,\s*){0}(null|.*),\s*(null|.*)(?:,|\]).*"wxPhraseLong":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\]).*"wxPhraseShort":\s*\[(?:null,\s*|".*",\s*){0}(null|".*"),\s*(null|".*")(?:,|\])
Wow, that's a long one and a great effort. I guess I should consider myself lucky with only around 950 lines for the whole skin and just 59 weather related measures that grab most of the relevant weather data from all the main sections (excluding, of course, the many duplicates and the obvious or irrelevant fields). All in all, you've done a great job. :great:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
gt57
Posts: 13
Joined: August 31st, 2009, 4:02 am

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by gt57 »

jsmorley wrote: June 17th, 2020, 2:48 pm Edit June 17, 2020 - Ok I think I might have fixed that issue with the "long day name" and the "short day name" (and other day month values) getting out of sync for an hour or two early in the morning.

Get the .rmskin in the first post of this thread.


I'm not forcing a days worth of seconds (86400) times the number of days from "today" anymore. That approach was based on the "observation time", and at some points in the day that could get out of sync with the long name of the day being returned as a string. I'm now using a field "validTimeLocal" that is returned for each day, and I'm pretty sure, or at least hoping, that this solves the issue.
Looks like this did the trick. I checked various locations in the wee hours of their morning and they are sync'd up.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by jsmorley »

gt57 wrote: June 18th, 2020, 12:57 am Looks like this did the trick. I checked various locations in the wee hours of their morning and they are sync'd up.
Excellent... Thanks.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by ikarus1969 »

jsmorley wrote: June 17th, 2020, 12:07 pm Yeah, It is my intent to do new versions for Moon, Pollen, and maybe AirQuality and Tides as soon as I catch my breath.
In case you've already caught your breath :) if not seen by you already i want to direct your attention to the following error in the moon-include.
It doesn't deliver the phase icons anymore. Instead the phase days are delivered.
Maybe there can be measures about both the days (the "age" of the moon) and of course the icon
RM Screenshot # 1.jpg
RM Screenshot # 2.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by Yincognito »

ikarus1969 wrote: June 18th, 2020, 5:51 am In case you've already caught your breath :) if not seen by you already i want to direct your attention to the following error in the moon-include.
It doesn't deliver the phase icons anymore. Instead the phase days are delivered.
Maybe there can be measures about both the days (the "age" of the moon) and of course the icon

RM Screenshot # 1.jpg
RM Screenshot # 2.jpg
Apart from your observation (which will probably be handled by jsmorley accordingly), just for information purposes, technically one could display more accurate representations of the moon phase based on the moon "age" / days value and the latitude (assuming the 29 or 30 moon icons for each day are already available, that is).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by jsmorley »

ikarus1969 wrote: June 18th, 2020, 5:51 am In case you've already caught your breath :) if not seen by you already i want to direct your attention to the following error in the moon-include.
It doesn't deliver the phase icons anymore. Instead the phase days are delivered.
Maybe there can be measures about both the days (the "age" of the moon) and of course the icon

RM Screenshot # 1.jpg
RM Screenshot # 2.jpg
I'll be working on the moon stuff this afternoon.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by jsmorley »

Edit June 18, 2020 - Revised the WeatherComJSONMoon.inc file, to include the new measure for Moon Phase Days/Age, as well as extending it to support the entire 15 days included in the JSON. I have also created a WeatherComJSONMoon7Day.inc file, which will only parse 7 days, if you don't want or need the full 15.

Get the rmskin in the first post of this thread.
nikko
Posts: 44
Joined: December 5th, 2017, 5:58 pm

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by nikko »

hello. please explain somebody what this things do here RegExp=(?siU)"getSunV3DailyForecastUrlConfig":.*dayOfWeek":\s*\[(?:".*",\s*){0}(".*").*
thanx
SCR
Posts: 60
Joined: April 15th, 2015, 11:13 pm

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by SCR »

jsmorley wrote: June 18th, 2020, 6:46 pm Edit June 18, 2020 - Revised the WeatherComJSONMoon.inc file, to include the new measure for Moon Phase Days/Age, as well as extending it to support the entire 15 days included in the JSON. I have also created a WeatherComJSONMoon7Day.inc file, which will only parse 7 days, if you don't want or need the full 15.

Get the rmskin in the first post of this thread.
Thanks JSMorley. The new "Moon Phase Days/Age" is nice.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by Yincognito »

nikko wrote: June 19th, 2020, 7:42 pm hello. please explain somebody what this things do here RegExp=(?siU)"getSunV3DailyForecastUrlConfig":.*dayOfWeek":\s*\[(?:".*",\s*){0}(".*").*
thanx
Technically, it looks in a dot-all (i.e. including newline characters), case-insensitive and ungreedy (i.e. taking as less characters as possible when using *) fashion (by using the (?siU) regex flags) for:
- the string "getSunV3DailyForecastUrlConfig":
- followed by any character, any number of times (i.e. the .*)
- followed by the string dayOfWeek":
- followed by any number of spaces (i.e. \s*)
- followed by a [ (i.e. \[, as [ needs to be escaped preceding it with \ in regexp, since is a reserved character)
- followed by any quote enclosed string that is succeeded by a comma and any number of spaces, all of it taken 0 times (i.e. (?:".*",\s*){0}; of course, taking a string 0 times means no character at all, so the 0 quantifier was probably used in order to be consistent with a similar place where the quantifier is different from 0)
- followed by any quote enclosed string that can be then referenced as a capture, like \1, \2, etc. (i.e. (".*"))
- followed by any number of characters any number of times (i.e. .*)

In simple, non technical terms, it looks for the value of the first day of week in the daily forecast section of the weather.com JSON being parsed in the skin.

Hint: changing the quantifier above from, say, {0} to {1} will instead look for the value of the second day of week in the same section of the JSON (since a comma followed enclosed string is basically how a value is stored in a JSON array, like, for example, ["Sun", "Mon", "Tue"]). Further increasing the quantifier will "iterate" through the rest of the day of week values in the array.
Last edited by Yincognito on June 19th, 2020, 9:27 pm, edited 1 time in total.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth