Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change JSON Parser argument for weather.sh #457

Open
jackdeye opened this issue Dec 25, 2024 · 0 comments
Open

Change JSON Parser argument for weather.sh #457

jackdeye opened this issue Dec 25, 2024 · 0 comments

Comments

@jackdeye
Copy link

Hi,

I'd like to propose an improvement to __yrno() function in weather.sh. Currently, the argument passed into $jsonparser is incorrect, resulting in the weather not displaying.

Current implementation

In __yrno(), we have

if weather_data=$(curl --max-time 4 -s "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${TMUX_POWERLINE_SEG_WEATHER_LAT}&lon=${TMUX_POWERLINE_SEG_WEATHER_LON}"); then
        grep=$TMUX_POWERLINE_SEG_WEATHER_GREP_DEFAULT
	error=$(echo "$weather_data" | $grep -i "error")
	if [ -n "$error" ]; then
		echo "error"
		exit 1
	fi
	jsonparser="${TMUX_POWERLINE_SEG_WEATHER_JSON}"
	degree=$(echo "$weather_data" | $jsonparser -r .properties.timeseries[0].data.instant.details.air_temperature)
	condition=$(echo "$weather_data" | $jsonparser -r .properties.timeseries[0].data.next_1_hours.summary.symbol_code)

This fails because .properties.timeseries[0] is not valid. You can verify this yourself by running the following:
curl --max-time 4 -s "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=$LAT&lon=$LON" | jq -r .properties.timeseries[0]
with any $LAT and $LON.

Proposed change

Instead, we can do the following:

degree=$(echo "$weather_data" | $jsonparser -r '.properties.timeseries | .[0].data.instant.details.air_temperature') 
condition=$(echo "$weather_data" | $jsonparser -r '.properties.timeseries | .[0].data.next_1_hours.summary.symbol_code')

Verification of Code Validity

I have checked that the code is valid with the following:
curl --max-time 4 -s "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=$LAT&lon=$LON" | jq -r '.properties.timeseries | .[0].data.instant.details.air_temperature' As this does return the correct temperature.

Request

I’d be happy to submit a Pull Request with the implementation. Let me know your thoughts!

Thanks for considering this suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant