It is currently September 23rd, 2020, 1:01 pm

⭐ Weather.com - Parsing the V3 JSON - NEW!

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
SilverAzide
Posts: 954
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by SilverAzide »

jsmorley wrote: August 1st, 2020, 6:52 pm Ah, so if it transitions from having one or more alerts to having none. It fails. I assume this is using WeatherComJSONAlerts.inc ?
Correct... :( Although for me it is barfing on not having any alerts even at the start, but on the second refresh (the first is always clean).
Gadgets Wiki GitHub More Gadgets...
User avatar
jsmorley
Developer
Posts: 21386
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by jsmorley »

SilverAzide wrote: August 1st, 2020, 9:24 pm Correct... :( Although for me it is barfing on not having any alerts even at the start, but on the second refresh (the first is always clean).
Simply replace the contents of WeatherComJSONAlerts.inc with this:

Code: Select all

; =================================================================================================
; WeatherComJSONAlerts.inc by JSMorley
; "Weather.com - Parsing the JSON" (https://forum.rainmeter.net/viewtopic.php?f=118&t=34628)
;
; Requires that WeatherComJSONVariables.inc and WeatherComJSONMeasures.inc
; be @Included in the skin before this file.
;
; Updated July 31, 2020
; ==================================================================================================

[@AlertsParent]
Measure=WebParser
Group=Parents
URL=[@EntireSiteSuperParent]
Disabled=1
LogSubstringErrors=0
StringIndex=1
RegExp=(?siU)"v3alertsHeadlines":(?(?=.*{.*,"alerts":).*{.*,"alerts":.*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*(?(?=.*{"detailKey").*:".*",.*,"eventDescription":"(.*)","severityCode":(.*),"severity":"(.*)",.*,"headlineText":"(.*)",.*}).*)

[@Alert1Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=1
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert1SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=2
Substitute=#CommonSubstitute#

[@Alert1Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=3
Substitute=#CommonSubstitute#

[@Alert1Text]
Measure=WebParser
Url=[@AlertsParent]
DecodeCharacterReference=1
StringIndex=4
Substitute=#CommonSubstitute#

[@Alert2Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=5
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert2SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=6
Substitute=#CommonSubstitute#

[@Alert2Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=7
Substitute=#CommonSubstitute#

[@Alert2Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=8
DecodeCharacterReference=1
Substitute=#CommonSubstitute#

[@Alert3Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=9
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert3SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=10
Substitute=#CommonSubstitute#

[@Alert3Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=11
Substitute=#CommonSubstitute#

[@Alert3Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=12
DecodeCharacterReference=1
Substitute=#CommonSubstitute#

[@Alert4Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=13
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert4SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=14
Substitute=#CommonSubstitute#

[@Alert4Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=15
Substitute=#CommonSubstitute#

[@Alert4Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=16
DecodeCharacterReference=1
Substitute=#CommonSubstitute#

[@Alert5Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=17
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert5SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=18
Substitute=#CommonSubstitute#

[@Alert5Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=19
Substitute=#CommonSubstitute#

[@Alert5Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=20
DecodeCharacterReference=1
Substitute=#CommonSubstitute#

[@Alert6Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=21
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert6SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=22
Substitute=#CommonSubstitute#

[@Alert6Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=23
Substitute=#CommonSubstitute#

[@Alert6Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=24
DecodeCharacterReference=1
Substitute=#CommonSubstitute#

[@Alert7Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=25
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert7SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=26
Substitute=#CommonSubstitute#

[@Alert7Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=27
Substitute=#CommonSubstitute#

[@Alert7Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=28
DecodeCharacterReference=1
Substitute=#CommonSubstitute#

[@Alert8Description]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=29
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute=#CommonSubstitute#
DynamicVariables=1

[@Alert8SeverityCode]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=30
Substitute=#CommonSubstitute#

[@Alert8Severity]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=31
Substitute=#CommonSubstitute#

[@Alert8Text]
Measure=WebParser
Url=[@AlertsParent]
StringIndex=32
DecodeCharacterReference=1
Substitute=#CommonSubstitute#
The absence of any alerts was handled a bit differently in the embedded JSON on the site from how it is in the API, and I needed to add a new "outer" lookahead-assertion to account for no data at all.

I didn't spot this since I live right on the Potomac River, and there are virtually ALWAYS at least one low-level "Small Craft Advisory" alerts in my feed any day of the week whose name ends in "y".

This will be corrected in the file the next time I distribute new .inc files, which likely won't be long, since I want to get that "pollen" stuff in soon.
User avatar
SilverAzide
Posts: 954
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by SilverAzide »

jsmorley wrote: August 1st, 2020, 10:14 pm Simply replace the contents of WeatherComJSONAlerts.inc with this:
Yep, that did the trick! Thanks!!
Gadgets Wiki GitHub More Gadgets...
User avatar
VClouds
Posts: 78
Joined: April 7th, 2010, 2:34 pm

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by VClouds »

In my weather skin, when clicking the city name at the top has always opened the city page in the weather.com website.
Using this url: https://weather.com/#Language#/weather/today/l/#LocationCode#

Now after converting to the new Latitude & Longitude method instead of the weather code one, that url obviously does not work anymore.

I know that I can force the user to also enter the location code in addition to the coordinates and that will fix this, but that is something I prefer not to do as it will confuse a lot of my users.

So I wonder if there's some alternative url that uses Latitude & Longitude to open the city page in the weather.com site?
User avatar
jsmorley
Developer
Posts: 21386
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by jsmorley »

VClouds wrote: August 2nd, 2020, 10:49 am In my weather skin, when clicking the city name at the top has always opened the city page in the weather.com website.
Using this url: https://weather.com/#Language#/weather/today/l/#LocationCode#

Now after converting to the new Latitude & Longitude method instead of the weather code one, that url obviously does not work anymore.

I know that I can force the user to also enter the location code in addition to the coordinates and that will fix this, but that is something I prefer not to do as it will confuse a lot of my users.

So I wonder if there's some alternative url that uses Latitude & Longitude to open the city page in the weather.com site?
LeftMouseUpAction=[https://weather.com/weather/today/l/#Latitude#,#Longitude#]
User avatar
VClouds
Posts: 78
Joined: April 7th, 2010, 2:34 pm

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by VClouds »

jsmorley wrote: August 2nd, 2020, 11:29 am LeftMouseUpAction=[https://weather.com/weather/today/l/#Latitude#,#Longitude#]
Excellent! Thank you! :)
User avatar
Yincognito
Posts: 2588
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by Yincognito »

VClouds wrote: August 2nd, 2020, 10:49 am In my weather skin, when clicking the city name at the top has always opened the city page in the weather.com website.
Using this url: https://weather.com/#Language#/weather/today/l/#LocationCode#

Now after converting to the new Latitude & Longitude method instead of the weather code one, that url obviously does not work anymore.

I know that I can force the user to also enter the location code in addition to the coordinates and that will fix this, but that is something I prefer not to do as it will confuse a lot of my users.

So I wonder if there's some alternative url that uses Latitude & Longitude to open the city page in the weather.com site?
jsmorley wrote: August 2nd, 2020, 11:29 amLeftMouseUpAction=[https://weather.com/weather/today/l/#Latitude#,#Longitude#]
Actually, you can do even better. Didn't mentioned it as the Nominatim variant of finding your latitude and longitude was independent, flexible and didn't require an API key and frankly I didn't try out these URLs until now, but one can do pretty much the same in weather.com:

Code: Select all

https://api.weather.com/v3/location/search?query=Fort Hunt&locationType=city&language=en-CA&format=json&apiKey=<ApiKey>
or, even more detailed (didn't know jsmorley's home address, so there is more than one result here too, unlike my case which is pretty much unique and outputs a single result):

Code: Select all

https://api.weather.com/v3/location/search?query=Fort Hunt, Virginia, United States&locationType=address&language=en-CA&format=json&apiKey=<ApiKey>
So basically you'll get a JSON with the possible locations, that you can parse and find out the latitude and longitude to use for the main request to the site for the weather JSON.
User avatar
jsmorley
Developer
Posts: 21386
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by jsmorley »

Yincognito wrote: August 2nd, 2020, 12:53 pm Actually, you can do even better. Didn't mentioned it as the Nominatim variant of finding your latitude and longitude was independent, flexible and didn't require an API key and frankly I didn't try out these URLs until now, but one can do pretty much the same in weather.com:

Code: Select all

https://api.weather.com/v3/location/search?query=Fort Hunt&locationType=city&language=en-CA&format=json&apiKey=<ApiKey>
or, even more detailed (didn't know jsmorley's home address, so there is more than one result here too, unlike my case which is pretty much unique and outputs a single result):

Code: Select all

https://api.weather.com/v3/location/search?query=Fort Hunt, Virginia, United States&locationType=address&language=en-CA&format=json&apiKey=<ApiKey>
So basically you'll get a JSON with the possible locations, that you can parse and find out the latitude and longitude to use for the main request to the site for the weather JSON.
Yeah, there are a lot of ways to get the latitude / longitude for a given location.

This is probably my favorite:

https://forum.rainmeter.net/viewtopic.php?f=118&t=34628&start=530#p180890

As then you can have a link like:

https://www.google.com/maps/search/#Latitude#,#Longitude#

in your skin, and it will jump straight to your actual house in Google Maps, confirming that the skin is in fact using the right location.
User avatar
Yincognito
Posts: 2588
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by Yincognito »

jsmorley wrote: August 2nd, 2020, 12:59 pm Yeah, there are a lot of ways to get the latitude / longitude for a given location.
Yep, but it just occured to me that I might have misunderstood VClouds' question in the first place... :???:
User avatar
Yincognito
Posts: 2588
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Weather.com - Parsing the V3 JSON - NEW!

Post by Yincognito »

jsmorley wrote: August 2nd, 2020, 12:59 pm Yeah, there are a lot of ways to get the latitude / longitude for a given location.

This is probably my favorite:

https://forum.rainmeter.net/viewtopic.php?f=118&t=34628&start=530#p180890

As then you can have a link like:

https://www.google.com/maps/search/#Latitude#,#Longitude#

in your skin, and it will jump straight to your actual house in Google Maps, confirming that the skin is in fact using the right location.
Indeed.