Skip to content

Commit c36f6c3

Browse files
authored
Merge pull request #500 from erikw/weather_ua
Set User Agent for met.no call
2 parents 3a4a688 + cf83a97 commit c36f6c3

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Please update your custom themes and segments now. [#489](https://github.com/eri
2121
- `now_playing.sh`: removed Spotify though wine. Not likely this is used anymore. If someone still uses, shout at me and I'll add it back :-). [#473](https://github.com/erikw/tmux-powerline/pull/473)
2222
- `weather.sh`: Removed GNU Grep dependency [#468](https://github.com/erikw/tmux-powerline/pull/468)
2323
- `cpu.sh`: Removed GNU Grep dependency [#472](https://github.com/erikw/tmux-powerline/pull/472)
24+
### Fixed
25+
- Set custom User Agent for weather segment's met.no API call. [#500](https://github.com/erikw/tmux-powerline/pull/500)
2426

2527

2628
## [3.1.0] - 2025-03-03

lib/util.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ tp_round() {
7777
env printf "%.${digits}f" "$(echo "scale=${digits};(((10^${digits})*${number})+0.5)/(10^${digits})" | bc)"
7878
};
7979

80+
81+
# Get tmux-powerline version.
82+
tp_version() {
83+
grep release: "$TMUX_POWERLINE_DIR_HOME/.semver.yaml" | cut -d' ' -f2
84+
}

segments/weather.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ __yrno() {
101101
return 1
102102
fi
103103

104-
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
104+
# Ref: https://api.met.no/doc/TermsOfService
105+
local user_agent
106+
user_agent="tmux-powerline/$(tp_version) (https://github.com/erikw/tmux-powerline)"
107+
108+
if weather_data=$(curl --max-time 4 -A "$user_agent" -s "https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${TMUX_POWERLINE_SEG_WEATHER_LAT}&lon=${TMUX_POWERLINE_SEG_WEATHER_LON}"); then
105109
error=$(echo "$weather_data" | grep -i "error")
106110
if [ -n "$error" ]; then
107111
tp_err_seg "Err: yr.no err: error in api return"

0 commit comments

Comments
 (0)