It is currently August 11th, 2020, 6:54 pm

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

Our most popular Tips and Tricks from the Rainmeter Team and others
EeK
Posts: 11
Joined: January 28th, 2020, 1:26 am

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by EeK »

Guys, did weather skins break again? Mine stopped working yesterday. I even posted here about it, with a screenshot of my desktop, but, apparently, it was removed.
User avatar
jsmorley
Developer
Posts: 21240
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Weather.com - Parsing the V3 JSON

Post by jsmorley »

EeK wrote: July 31st, 2020, 2:38 am Guys, did weather skins break again? Mine stopped working yesterday. I even posted here about it, with a screenshot of my desktop, but, apparently, it was removed.
https://forum.rainmeter.net/viewtopic.php?f=13&t=35773
User avatar
jsmorley
Developer
Posts: 21240
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

Ok, I think I have fully addressed the new issues with the weather.com site.

Please get the .rmskin in the first post of this thread.


ONE IMPORTANT NOTE!


The new approach of using the API for the weather.com JSON requires a change to how you access a particular location.

All of the location "codes", like USVA0944 or bbd510e73cb5870f973cea9253bb1f9bfe239a129dfc2b89589cbb6d2d46b4bc or 22308 and such are NO LONGER SUPPORTED.

The new approach requires that you provide a Latitude and Longitude in the WeatherComJSONVariables.inc file. See that file for details on how you can get that for your location.

Please read WeatherCOMJSONVariables.inc carefully, it HAS changed.

Code: Select all

[Variables]

; NOTE that Location Codes like USVA0944 or other types of codes are no longer supported.

; You must use location Latitude and Longitude.

; You can right click the skin and select "Choose location" to use a litle skin I wrote.
; Simply type any search string into "Search For Location", hit Enter, then click
; the magnifying glass at the bottom left.
; Once you have found the location you want, click on the Latitude,Longitude numbers
; on the right to set that value and refresh the main weather skin.
; Click the Name of the location on the left to see the location on a map in your browser.
; 
; These values can also be found manually for your location at:
; https://nominatim.openstreetmap.org/search.php?q=Your Address Text&format=json
; Where "Your Address Text" can be pretty much anything that can zero in on the location you want.
; https://nominatim.openstreetmap.org/search.php?q=Fort Hunt, Virginia&format=json
; https://nominatim.openstreetmap.org/search.php?q=22308&format=json
; https://nominatim.openstreetmap.org/search.php?q=The White House, Washington D.C.&format=json
; Then copy the lat: and lon: values from that site and paste them below.

Latitude=38.723249
Longitude=-77.069950
;Fort Hunt, Virginia
;Latitude=38.723249
;Longitude=-77.069950
;Auburn, Alabama
;Latitude=32.5971687
;Longitude=-85.5565993

;Latitude=25.7742658
;Longitude=-80.1936589

; Language used for string values returned in the data.
; If another language is desired the correct code can be found at:
; https://admin.rainmeter.net/LanguageCodes.php
; For example, French as used in France would be Language=fr-FR

Language=en-US
;Language=fr-FR
;Language=hu-HU

; Units of measure. This must be one of the following lower case letters:
; e		This is "Imperial", using Fahrenheit for temperatures.
; m		This is "Metric", using Celsius for temperatures.
; h		This is "Hybrid", used primarily in the UK. Celsius for temperatures, but miles for distances.

Units=e
;Units=m
;Units=h

; How often to update the weather information. Default and recommended is 600, which would be 10 minutes.

UpdateRate=600

; Date and time formats you desire.
; See https://docs.rainmeter.net/manual/measures/time/#FormatCodes 
; For formatting codes to use.

DateFormat=%A, %B %#d, %Y
TimeFormat=%#I:%M %p

; Don't change any below here.

APIKey=d522aa97197fd864d36b418f39ebb323

CommonSubstitute='"':"","^null$":"","\\u002F":"/","\\u005C":"\","\\u003C":"<","\\u003E":">"
URLSite=https://api.weather.com/v3/aggcommon/v3-wx-observations-current;v3-wx-forecast-daily-15day;v3alertsHeadlines;v3-location-point?format=json&geocode=#Latitude#,#Longitude#&units=#Units#&language=#Language#&apiKey=#APIKey#
You do not have the required permissions to view the files attached to this post.
jazde86
Posts: 1
Joined: July 31st, 2020, 9:31 pm

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

Post by jazde86 »

Hey jsmorley, thanks for the update. I would prefer if you could replace the LocationName with the City string, as the website does not resolve to the precise place where you live too. Or add it as LocationCity maybe, because it's in the JSON available. More options are always welcome.

Thanks for your effort.
User avatar
jsmorley
Developer
Posts: 21240
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

While that Latitude / Longitude skin I included works pretty well, if you want to be really precise on the location, do this:

- Go to https://www.google.com/maps
- Search for and find your house on the map. Zoom in and right-click on your bedroom.
- Select "What's here?" from the context menu.
- A small card will appear, with the latitude and longitude. Click on the latitude and longitude.
- That latitude and longitude will appear in a sidebar window on the left. Copy them.
- Paste them in as Latitude= and Longitude= in WeatherComJSONVariables.inc
- Refresh

This will reflect your actual location, accurate to a few feet or so.

https://support.google.com/maps/answer/18539?co=GENIE.Platform%3DDesktop&hl=en

Now, the display name that is returned, and to be honest the actual station where the weather is observed isn't actually going to be "Bob's Bedroom", unless you live at the airport maybe, but some administrative district or town name that is nearby. Still, this approach is going to be as accurate as is possible for your location.

If I right-click the skin and select the display name at the top of the context menu, it goes directly to my bedroom in Google Maps. That's accuracy.

Using Latitude / Longitude is certainly more accurate from the standpoint of actual, physical location than any of the "location codes" that the site uses, but the downside is that a code like USVA0944 was tied in a database to a display name of "Fort Hunt", which pleased me, since that is what my "area" is called. Latitude and Longitude return a display name that is a little more general, probably the nearest town. However, the weather itself is as accurate as it possibly can be. Hey, just use a String measure and hard code "Gator Gulch" or whatever you want for display name if you like...
User avatar
jsmorley
Developer
Posts: 21240
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

jazde86 wrote: July 31st, 2020, 9:36 pm Hey jsmorley, thanks for the update. I would prefer if you could replace the LocationName with the City string, as the website does not resolve to the precise place where you live too. Or add it as LocationCity maybe, because it's in the JSON available. More options are always welcome.

Thanks for your effort.
My reasoning behind what I get is that there are really only three fields that as I see it are always populated. AdminDistrict (which is state in the US, and some other region name in other countries), Country (there is always a country), and DisplayName (there is always a display name).

All the other fields, including "city", may or may not be populated, and so you can't really depend on them in a generic way.

It's unlikely but possible that AdminDistrict could be null as well, but since "Springfield US" means exactly nothing, as there are hundreds of towns named Springfield in the US, I simply had to get the "state / region". You can use IfMatch to deal with missing AdminDistrict values if you like.

Still, your observation of "the more the merrier" has some charm. I'll look at getting and offering ALL the fields returned by "location", and leave it up to you which ones you want to use, and how you want to deal with null values for many of them.
User avatar
ikarus1969
Posts: 375
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

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

Post by ikarus1969 »

@jsmorley:

thank you very much for all the includes so we can easily concentrate on the contebnt of our skins!

One thing: could you please add a

Code: Select all

FormatLocale=#Language#
to the measure "[@CurrentObservationDate]" in all of your WeatherComJSONMeasures... -inc-files?
So that, eg. the weekday (or any other local date-part) would be in the locale we can set in the WeatherComJSONVariables.inc

Thank you very much!
User avatar
jsmorley
Developer
Posts: 21240
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

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

Post by jsmorley »

ikarus1969 wrote: August 1st, 2020, 6:18 am @jsmorley:

thank you very much for all the includes so we can easily concentrate on the contebnt of our skins!

One thing: could you please add a

Code: Select all

FormatLocale=#Language#
to the measure "[@CurrentObservationDate]" in all of your WeatherComJSONMeasures... -inc-files?
So that, eg. the weekday (or any other local date-part) would be in the locale we can set in the WeatherComJSONVariables.inc

Thank you very much!
Good idea. The next time I have to put out the .inc files that will be there. You can add it to yours in the meantime.
User avatar
SilverAzide
Posts: 928
Joined: March 23rd, 2015, 5:26 pm

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

Post by SilverAzide »

Sorry to report this, but I've noticed a regex error popping up: RegExp matching error (-1) ([@AlertsParent])

It only happens on the second and later calls to fetch the weather.com data; i.e., the initial call is fine. Perhaps due to the measure being enabled on the second/subsequent calls? Also, it only happens when there are no weather alerts for the location.
Gadgets DeviantArt More...
User avatar
jsmorley
Developer
Posts: 21240
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, 5:32 pm Sorry to report this, but I've noticed a regex error popping up: RegExp matching error (-1) ([@AlertsParent])

It only happens on the second and later calls to fetch the weather.com data; i.e., the initial call is fine. Perhaps due to the measure being enabled on the second/subsequent calls? Also, it only happens when there are no weather alerts for the location.
Ah, so if it transitions from having one or more alerts to having none. It fails. I assume this is using WeatherComJSONAlerts.inc ?