It is currently March 29th, 2020, 12:27 am

⭐ Searching for weather.com Location Codes (USVA0944)

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

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by jsmorley »

I think the only thing you can be 100% sure of is the measure [@LocationName] which is based on the JSON field displayName in the return, and as far as I can tell, will always be there. It won't necessarily have your city or country as a part of it, but might be all you need to display something that ensures you are getting the location you think you are.
User avatar
SilverAzide
Posts: 713
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by SilverAzide »

jsmorley wrote:
February 26th, 2020, 2:39 pm
I think the only thing you can be 100% sure of is the measure [@LocationName] which is based on the JSON field displayName in the return, and as far as I can tell, will always be there. It won't necessarily have your city or country as a part of it, but might be all you need to display something that ensures you are getting the location you think you are.
A question... The way the location JSON regex is constructed, it is grabbing the lat, long, displayname from the first chunk of location data, then grabbing the adminDistrict, etc., from the second (or later) chunk. His problem is the second chunk of data failed, so the entire regex failed (thus all the location measures are blank). Could this situation be avoided if the Location parent measure was split into two, so you would grab the lat/long/displayName values from the first chunk of data, then the adminDistrict/etc values from the "last" chunk (which could be the first chunk if there is no second chunk)?
DeviantArt Gadgets More...
User avatar
jsmorley
Developer
Posts: 20425
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by jsmorley »

I'm not sure I wouldn't lean to an approach where the regex tries to get the adminDistrict and country from the "last" chunk of data, which seems almost all the time (although apparently not 100%) the most reliable. Then have the user create some "fallback" #VarNames# for those two bits of information. If an IFMatch on the two measures returns an empty string, you just use the #VarName# instead.
User avatar
SilverAzide
Posts: 713
Joined: March 23rd, 2015, 5:26 pm

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by SilverAzide »

jsmorley wrote:
February 26th, 2020, 4:52 pm
I'm not sure I wouldn't lean to an approach where the regex tries to get the adminDistrict and country from the "last" chunk of data, which seems almost all the time (although apparently not 100%) the most reliable. Then have the user create some "fallback" #VarNames# for those two bits of information. If an IFMatch on the two measures returns an empty string, you just use the #VarName# instead.
Yes, agreed, the way the JSON regex is working now is good and seems to get the best data almost all the time. But what I meant in my question is when the second block of location data is a failure (see the spoiler snippet in my post), then the entire regex fails and all of the location measures are blank. You won't just be missing the admin stuff, you end up missing everything... :( I tried tweaking the regex, but made things worse.

(P.S.: this conversation really belongs in the weather.com JSON thread, not this one... Sorry about that)
Last edited by SilverAzide on February 26th, 2020, 5:37 pm, edited 1 time in total.
DeviantArt Gadgets More...
User avatar
jsmorley
Developer
Posts: 20425
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by jsmorley »

SilverAzide wrote:
February 26th, 2020, 5:32 pm
Yes, agreed, the way the JSON regex is working now is good and seems to get the best data almost all the time. But what I meant in my question is when the second block of location data is a failure (see the spoiler snippet in my post), then the entire regex fails and all of the location measures are blank. You won't just be missing the admin stuff, you end up missing everything... :( I tried tweaking the regex, but made things worse.
Thing is, 99.9% of the time data is "missing" but properly formatted with a string value of a literal null. In order to address improperly formatted JSON, when it actually blows up, that would be more complicated than I think I want to get into. I really don't want to have to have a bunch of look-arounds (forwards and backwards) in this regular expression if I can help it.
User avatar
Yincognito
Posts: 1070
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by Yincognito »

Oh, this thing again... Yeah, it's a bit annoying when it happens. Just saying, when you build the regex a certain way (like extracting the big chunks first, to use them with StringIndex2 later), no look around is needed, just a simple ? to switch from ungreedy to greedy, and grab the last (the 2nd, thus) subsection of "Location". Optionally, one can include a field that he doesn't want to be null (testing for something like ".+") and the regex will automatically extract either the 1st or the 2nd subsection (depending on greediness) only if its said field isn't null, and the other of the two if the field in the initially "preferred" subsection is null.

Also, one other thing I found out: the order of fields / sections in a JSON is arbitrary, meaning that when that changes, our current regexes would fail.
Mrslazygeneral
Posts: 2
Joined: March 26th, 2020, 2:04 pm

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by Mrslazygeneral »

I am lost. I tried editing the location, and it is not working. Just goes back to Fort Hunt Virginia. I clicked on the search button after i typed everything in, checked in the data file to make sure i had the right location (it is in the data file) and copied the code over from the data file to make sure it was the correct code (USVT0017) and it still defaults back to Fort Hunt Virginia......

**UPDATE**I edited all the files i found in the Weather.com file to reflect the code. It is working now, but the Choose Location option is not working at all.
Last edited by Mrslazygeneral on March 26th, 2020, 2:14 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 20425
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by jsmorley »

Be sure you hit Enter after you put data in each field.


test1.gif
You do not have the required permissions to view the files attached to this post.
Mrslazygeneral
Posts: 2
Joined: March 26th, 2020, 2:04 pm

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by Mrslazygeneral »

jsmorley wrote:
March 26th, 2020, 2:14 pm
test1.gif
Yea - I tried that, could not understand why it wasnt working. I blame it on myself - as it just wasnt working. Figured I was doing something wrong.

As a side note - this is my choice for weather rainmeter apps. I have tried others, but this one has been consistently great. Thanks!
User avatar
jsmorley
Developer
Posts: 20425
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ Searching for weather.com Location Codes (USVA0944)

Post by jsmorley »

Check in WeatherComCodes.ini and be sure these values are correct for your skin:

Code: Select all

; Change FileToWrite to the .ini or .inc file you wish to update.
FileToWrite=#@#WeatherComJSONVariables.inc
; Change VariableToWrite to the name of the [Variable] in FileToWrite.
VariableToWrite=LocationCode
; Change ConfigToRefresh to the config that will be using the location code variable.
ConfigToRefresh=#ROOTCONFIG#