It is currently March 29th, 2024, 9:01 am

⭐ Weather.com - Parsing the V3 JSON

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

Re: ⭐ weather.com - Parsing the JSON

Post by jsmorley »

At the end of the day, it might indeed be that the most accurate way is to use the lat,long as input to the URL. You may not like the displayName it comes up with, but I think it will use the closest "observation station" and be correct.

For instance if I go to Google Maps and find "Harlem" in New York City / Manhattan, then use the lat,long returned in the Google Maps URL as input to weather.com, it uses a displayName of "Manhattan", which is close enough. I assume the actual weather will be as good as it can do for an area as specific as "Harlem". As it turns out, there is no locid that can be matched on the name "Harlem" in New York. Georgia, sure, Montana, yep. New York, no.

I'm betting that in this case, the "first" set of location information will be spotty at best.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ weather.com - Parsing the JSON

Post by SilverAzide »

Yes! This is the exact scenario I run into, even though my podunk little town has 100th the population and size of New York City.

The good news for us is that the TWC URL still allows short codes, long codes, and lat/longs without much complaining, so users have the option of whichever they prefer. This is a much nicer API than Dark Sky, which is lat/long or nothing (not to mention TWC has way better data).
Gadgets Wiki GitHub More Gadgets...
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ weather.com - Parsing the JSON

Post by jsmorley »

I'm just not convinced there is an accurate way to get lat,long for your location with WebParser. Yes, I know there are sites that will return what it detects as your location, but they only work right in a "browser", which can provide the far more accurate "GeoLocation" information your browser gets. With WebParser, which isn't a browser, and can't answer any questions the site might be asking, (permissions being one of them) I suspect you will get what is returned for your raw IP Address, which will be the closest "point of presence" for your ISP. For me, that is in Chantilly, Virginia, which isn't even close to where my house is. It's like a 30-minute drive.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ weather.com - Parsing the JSON

Post by Yincognito »

jsmorley wrote: February 20th, 2020, 3:24 pmAt the end of the day, it might indeed be that the most accurate way is to use the lat,long as input to the URL.
I remember you mentioning it somewhere in your posts (and it's probably mentioned also in some of the docs I linked to), but I don't seem to find that post at the moment, so I'll ask again: what is the URL format when using LAT and LONG instead of a location code?
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 JSON

Post by jsmorley »

Yincognito wrote: February 20th, 2020, 3:50 pm I remember you mentioning it somewhere in your posts (and it's probably mentioned also in some of the docs I linked to), but I don't seem to find that post at the moment, so I'll ask again: what is the URL format when using LAT and LONG instead of a location code?
https://weather.com/en-US/weather/today/l/38.7235031,-77.0663437

Pretty much any granularity in the decimal portions of the numbers is supported.

https://weather.com/en-US/weather/today/l/38.724,-77.066

The more granular lat / long is, the more accurate it is, but at some point that has diminishing returns on something as broad as the weather. The weather in my front yard is very similar to the weather in my back yard, or the 7-11 down the street, or more to the point, the closest observation station to me.

What weather.com "returns" seems to always be at most to three decimal places.

At the end of the day, what I want is to zero in on the observation station that is closest to me, which is what measures the weather, then have it "display" my exact location in displayName. Yes, that is going to be somewhat "cosmetic" and "feel good", but that is the best result for me.
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ weather.com - Parsing the JSON

Post by Yincognito »

Thanks. What's interesting is that the 1st subsection of "Location" displays here the neighborhood and a non-null locale4 field, while the 2nd subsection doesn't. I didn't have such an example to analyze before.

Now, I'm trying to find a free service that can provide an accurate lat/long for a location that's present in the URL. So far, most of them work by "Javascripting" the location one enters in a search field on the page, rather than use a part of an URL query to set the location.

EDIT: Found one: GeoCodeXYZ. It seems free of charge, fast and the output can be either xml, json, etc. I can get the lat and long of your location just by entering this URL, and it also has a nice field called confidence to show the likeness of the provided coordinates being correct for a (possibly, non-unique) location. It works for my city as well, just by entering its name, without any other info (granted, there aren't many "duplicate" locations for my city name).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ weather.com - Parsing the JSON

Post by SilverAzide »

Here's the API you are looking for :)

https://nominatim.openstreetmap.org/search?city=Fort%20Hunt&format=xml&addressdetails=1

Search for the city/place, get the lat/long. But it just gives you the center of town. If you want more accurate results, I don't know of an API. I just have been using Google Maps and dropping a pin.
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ weather.com - Parsing the JSON

Post by Yincognito »

SilverAzide wrote: February 20th, 2020, 4:52 pm Here's the API you are looking for :)

https://nominatim.openstreetmap.org/search?city=Fort%20Hunt&format=xml&addressdetails=1

Search for the city/place, get the lat/long. But it just gives you the center of town. If you want more accurate results, I don't know of an API. I just have been using Google Maps and dropping a pin.
That's even better, as it's faster that what I found. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ weather.com - Parsing the JSON

Post by SilverAzide »

Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 7029
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ weather.com - Parsing the JSON

Post by Yincognito »

Indeed. If I simply entered the road / avenue name in my case, it put the actual road name in the "artwork" field. If I entered the avenue name preceeded by the word for "avenue" in my language, it gave me 2 results, so in the latter case I had to add &limit=1 to the query, for easier (potential) parsing.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth