It is currently April 18th, 2024, 6:18 am

⭐ Weather.com - Parsing the V3 JSON

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: ⭐ weather.com - Parsing the JSON

Post by fonpaolo »

Sorry I don't understand jsmorley...
Is it more complicated to download (and use) only one part than to download (and use) the whole code contained in the web page? :?

...and to be clear, I tried to understand the .inc files, but I can't even understand what "@" stands for in your [@WhateverMeasure] O.O :-(
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ weather.com - Parsing the JSON

Post by jsmorley »

It's really pretty simple.

If you @Include the files:

WeatherComJSONVariables.inc
WeatherComJSONMeasures.inc

into your skin, I have done all the work to create all the measures you will need.

So in theory, you don't need ANY measures in your skin at all, just delete them. I'll take care of the measures, you just need to worry about the meters.

Then use the reference below, and in the meters in your skin, where you were using MeasureName=MyCurrentTemperature or whatever, just change that to the appropriate measure name from the .inc file. That would be MeasureName=@CurrentTemperature.

The @ at the beginning of my measure names is of no functional purpose. Don't get confused by that. I only did it that way so it is easy to spot them in the results in About / Skins. They start with @ in order to make it easy to see what is coming from the @Include files.


Code: Select all

[@UnitsType] : This will be "m" or "e"
[@UnitsTemperature] : This will be "C" or "F"
[@UnitsSpeed] : This will be "km/h" or "mph"
[@UnitsDistance] : This will be "km" or "mi"
[@UnitsAccumulation] : This will be "cm" or "in"
[@UnitsPrecipitation] : This will be "mm" or "in"
[@UnitsPressure] This will be "mb" or "in"

[@LocationLatitude] : i.e. 38.805
[@LocationLongitude] : i.e -77.047
[@LocationAdminDistrict]
[@LocationAdminDistrictCode]
These AdminDistrict values will vary in meaning depending on where you live.
In the US, this will be the "state". Other places it may be "region".
[@LocationCountry] : i.e. United States of America
[@LocationCountryCode] : i.e. US
[@LocationName] : Location Display Name - Generally the "city"
[@LocationLanguageCode] : i.e. en-US
[@LocationTimeZoneAbbreviation] : i.e. EST

[@CurrentPressure]
[@CurrentPressureChangeTrend]
[@CurrentPressureCode]
[@CurrentPressureChangeAmount]
[@CurrentDewPoint]
[@CurrentFeelsLike]
[@CurrentWindGust]
[@CurrentHumidity]
[@CurrentIcon]
[@CurrentObservationTimeStamp]
[@CurrentObservationDate] 
Automatically uses defined #Lanaguage# (i.e. en-US) to translate Month/Day names.
[@CurrentObservationTime]
[@CurrentConditions]
[@CurrentPrecipitationLast24Hours] : Use @UnitsPrecipitation
[@CurrentSnowDepth] : Use @UnitsAccumulation
[@CurrentTemperature]
[@CurrentTemperatureMaxSince7AM]
[@CurrentUVIndex] : A range of 1-10
[@CurrentUVDescription]
[@CurrentVisibilityDistance]
[@CurrentWindSpeed]
[@CurrentWindDirectionCompass] : i.e. NNW
[@CurrentWindDirectionDegrees] : i.e. 220
[@CurrentSunriseTimeStamp]
[@CurrentSunriseTime]
[@CurrentSunSetTimeStamp]
[@CurrentSunsetTime]

[@ForecastTodayDayLong] : Full day of the week i.e. Saturday
[@ForecastTodayDayShort] : Always "Today", or an empty string. See Note below.
[@ForecastTodayDayPrecipitationPercent] : Percentage likely
[@ForecastTodayDayPrecipitationAmount] : Use @UnitsPrecipitation
[@ForecastTodayDayPrecipitationType] : "rain", "snow" or the generic "precip"
[@ForecastTodayDayTemperature]
[@ForecastTodayDayUVIndex] : A range of 1-10
[@ForecastTodayDayUVIndexDescription]
[@ForecastTodayDayIcon]
[@ForecastTodayDayConditions]
[@ForecastTodayDayNarrative]
[@ForecastTodayDayCloudPercent]
[@ForecastTodayDayWindDirectionCompass]
[@ForecastTodayDayWindDirectionDegrees]
[@ForecastTodayDayWindSpeed]
[@ForecastTodayDayHumidity]
[@ForecastTodayDaySnowRange] : Use @UnitsAccumulation
Note: At some point in the afternoon, all "TodayDay" measures except
[@ForecastTodayDayLong] will return an empty string. If [@ForecastTodayDayShort]
is an empty string, then it is "Tonight". There can't be a "forecast" for a part of day
that has already gone by. You must react to that, and perhaps use "TodayNight"
measures in their place. 

[@ForecastTodayNightShort] : Always "Tonight"
[@ForecastTodayNightPrecipitationPercent] : Percentage likely
[@ForecastTodayNightPrecipitationAmount] : Use @UnitsPrecipitation
[@ForecastTodayNightPrecipitationType] : "rain", "snow" or the generic "precip"
[@ForecastTodayNightTemperature]
[@ForecastTodayNightUVIndex] : A range of 1-10
[@ForecastTodayNightUVIndexDescription]
[@ForecastTodayNightIcon]
[@ForecastTodayNightConditions]
[@ForecastTodayNightNarrative]
[@ForecastTodayNightCloudPercent]
[@ForecastTodayNightWindDirectionCompass]
[@ForecastTodayNightWindDirectionDegrees]
[@ForecastTodayNightWindSpeed]
[@ForecastTodayNightHumidity]
[@ForecastTodayNightSnowRange] : Use @UnitsAccumulation

[@ForecastTodayMonthLong] : i.e. February
[@ForecastTodayMonthShort] : i.e. Feb
[@ForecastTodayDayOfMonth] : i.e. 15

[@ForecastDay2DayLong] : Full day of the week i.e. Sunday
[@ForecastDay2DayShort] : Short day of the week i.e. Sun
[@ForecastDay2DayPrecipitationPercent] : Percentage likely
[@ForecastDay2DayPrecipitationAmount] : Use @UnitsPrecipitation
[@ForecastDay2DayPrecipitationType] : "rain", "snow" or the generic "precip"
[@ForecastDay2DayTemperature]
[@ForecastDay2DayUVIndex] : A range of 1-10
[@ForecastDay2DayUVIndexDescription]
[@ForecastDay2DayIcon]
[@ForecastDay2DayConditions]
[@ForecastDay2DayNarrative]
[@ForecastDay2DayCloudPercent]
[@ForecastDay2DayWindDirectionCompass]
[@ForecastDay2DayWindDirectionDegrees]
[@ForecastDay2DayWindSpeed]
[@ForecastDay2DayHumidity]
[@ForecastDay2DaySnowRange] : Use @UnitsAccumulation

[@ForecastDay2NightShort] : Short day of the week i.e. Sun
[@ForecastDay2NightPrecipitationPercent] : Percentage likely
[@ForecastDay2NightPrecipitationAmount] : Use @UnitsPrecipitation
[@ForecastDay2NightPrecipitationType] : "rain", "snow" or the generic "precip"
[@ForecastDay2NightTemperature]
[@ForecastDay2NightUVIndex] : A range of 1-10
[@ForecastDay2NightUVIndexDescription]
[@ForecastDay2NightIcon]
[@ForecastDay2NightConditions]
[@ForecastDay2NightNarrative]
[@ForecastDay2NightCloudPercent]
[@ForecastDay2NightWindDirectionCompass]
[@ForecastDay2NightWindDirectionDegrees]
[@ForecastDay2NightWindSpeed]
[@ForecastDay2NightHumidity]
[@ForecastDay2NightSnowRange] : Use @UnitsAccumulation

[@ForecastDay2MonthLong] : i.e. February
[@ForecastDay2MonthShort] : i.e. Feb
[@ForecastDay2DayOfMonth] : i.e. 16

...

This will follow the same pattern for Day3 through Day6

1.jpg


So I guess my point isn't that it is more, or even particularly "complicated" at all to once again parse the entire weather.com website to pull out just the information you might want from the part of the site that is embedded JSON code. However, why in the world would you want to do that, and why would I want to get in the middle of it? Been there, done that, don't want the t-shirt.

It's not complicated at all to parse, but there is a LOT of it to wade through. My goal was to do that once and only once, and be done with it. Then just be able to drop the result of all that work into ANY skin, and not have to do it again.

There are more or less 250 distinct bit of information in the current weather and 6-day forecast weather on the site. That's 250+ measures you probably don't want, and certainly don't need, to create from scratch.

The idea is to separate the "back-end / measure" part of the work from the "front-end / meter" part of the work. You can just drop the back-end stuff into a skin, and Bob's Your Uncle, that's done. Then just concentrate on how you want it to "look". That's the creative and I would argue fun part of it anyway.

I would argue that there is no need to "understand" the contents of the .inc files. There is no real reason why you would ever even open them in a text editor. You simply need that reference above, so you know what @MeasureName to use in the skin when you want some particular bit of data.
You do not have the required permissions to view the files attached to this post.
User avatar
Hackit
Posts: 85
Joined: May 19th, 2010, 9:05 pm
Location: North of the Border

Re: ⭐ weather.com - Parsing the JSON

Post by Hackit »

Hi all, so i have been playing with a moon meter,i'm not interested in the moonset or moonrise. i'm looking to show days tell next full moon. from reading the WeatherComJSONMoon.inc it seems the file is for moonrise and moonset only.
would my understanding be correct?
if so, then to achieve days tell next full moon would need to have it's own .inc file like daystellfullmoon.inc, which would require a whole bunch of new coding.
am i understanding this correctly?
tnx
side note jsmorley you are absolutely brilliant to put this all together and do all the heavy lifting for most of us. this blows my mind how you find the time and energy to keep this moving forward. i'm so ever grateful for all you have done.
“Whether you think you can, or you think you can't – you're right”

DeviantArt Profile
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: ⭐ weather.com - Parsing the JSON

Post by jsmorley »

Hackit wrote: April 2nd, 2020, 1:24 pm Hi all, so i have been playing with a moon meter,i'm not interested in the moonset or moonrise. i'm looking to show days tell next full moon. from reading the WeatherComJSONMoon.inc it seems the file is for moonrise and moonset only.
would my understanding be correct?
if so, then to achieve days tell next full moon would need to have it's own .inc file like daystellfullmoon.inc, which would require a whole bunch of new coding.
am i understanding this correctly?
tnx
side note jsmorley you are absolutely brilliant to put this all together and do all the heavy lifting for most of us. this blows my mind how you find the time and energy to keep this moving forward. i'm so ever grateful for all you have done.
I'm not entirely sure you can do that at all with the information from weather.com. The moon information returned by the site is for the next 6 days, and there is no certainty at all that there will be a full moon within the next 6 days. Odds are in favor of not in fact...

You might need a different site altogether for what you want.

I'm no expert on moon phases, but maybe there is some math you can use to get from a date from the start of some particular phase to the start of some other particular phase without explicitly getting the date from the site. I don't know, there are a couple of guys on here who apparently have a relative that suffers from Lycanthropy, and know a lot more about it.

P.S. Just a nitpick, but It would be "until the next full moon" or "til the next full moon", not "tell next full moon". Not sure what you would want to "tell" the next full moon, maybe "I hate it that you are not in the data from weather.com!"
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: ⭐ weather.com - Parsing the JSON

Post by balala »

Hackit wrote: April 2nd, 2020, 1:24 pm i'm looking to show days tell next full moon.
Definitely can be done. I'm promoting again one of my works. My Mirage suite has a skin called SunMoon, which shows the current Moon phase and among others, the number of days to the next Full Moon. And unlike the vaste majority of such skins, it doesn't download these information from a website, but makes all needed calculations locally, through .lua scripts. Give it a try, if interested.
jsmorley wrote: April 2nd, 2020, 1:32 pm I'm no expert on moon phases, but maybe there is some math you can use to get from a date from the start of some particular phase to the start of some other particular phase without explicitly getting the date from the site.
There definitely is. See above.
User avatar
Hackit
Posts: 85
Joined: May 19th, 2010, 9:05 pm
Location: North of the Border

Re: ⭐ weather.com - Parsing the JSON

Post by Hackit »

thanks jsmorley,
appreciate the critique.
i'll do some searching, not sure i'll figure it out but i'll see what i can do.
love all the new options in the json weather by the way.
“Whether you think you can, or you think you can't – you're right”

DeviantArt Profile
User avatar
Hackit
Posts: 85
Joined: May 19th, 2010, 9:05 pm
Location: North of the Border

Re: ⭐ weather.com - Parsing the JSON

Post by Hackit »

balala wrote: April 2nd, 2020, 2:13 pm Definitely can be done. I'm promoting again one of my works. My Mirage suite has a skin called SunMoon, which shows the current Moon phase and among others, the number of days to the next Full Moon. And unlike the vaste majority of such skins, it doesn't download these information from a website, but makes all needed calculations locally, through .lua scripts. Give it a try, if interested.

There definitely is. See above.
wow this forum is by far the best i have ever been involved with, you guys are so helpful and friendly.
just wow.
i'll look into you skin, thanks.
“Whether you think you can, or you think you can't – you're right”

DeviantArt Profile
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: ⭐ weather.com - Parsing the JSON

Post by eclectic-tech »

Hackit wrote: April 2nd, 2020, 2:18 pm wow this forum is by far the best i have ever been involved with, you guys are so helpful and friendly.
just wow.
i'll look into you skin, thanks.
Balala's skin is self contained and works great! :thumbup:

Alternately, you might also want to look at Sgt. E. V. McKay skins using http://iohelix.net/moon/ moon data from the web.
visions4.png
You can view the info here: moon skins. 8-)
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16143
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: ⭐ weather.com - Parsing the JSON

Post by balala »

eclectic-tech wrote: April 2nd, 2020, 3:04 pm Balala's skin is self contained and works great! :thumbup:
No, in fact there is a great problem, I'm working with, these days. The Weather is still broken on the published package. Yep, I know I should have finished it by now and in fact I thought I did. But right before I planed to publish the rewritten package, I found a bug and these days I'm working on fixing it. But unfortunately due to my everyday other works, I'm not advancing as fast as I would like. Sooner or later I will publish it (I hope!), but so far it's not ready. Unfortunately (for me).
User avatar
Hackit
Posts: 85
Joined: May 19th, 2010, 9:05 pm
Location: North of the Border

Re: ⭐ weather.com - Parsing the JSON

Post by Hackit »

eclectic-tech wrote: April 2nd, 2020, 3:04 pm Balala's skin is self contained and works great! :thumbup:

Alternately, you might also want to look at Sgt. E. V. McKay skins using http://iohelix.net/moon/ moon data from the web.visions4.png
You can view the info here: moon skins. 8-)
Balala's skin is sick, weeks of work im sure.

thanks electric-tech the vision+weather worked perfectly.
“Whether you think you can, or you think you can't – you're right”

DeviantArt Profile