-
Notifications
You must be signed in to change notification settings - Fork 519
Added "auto" option for the weather section #464
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
Conversation
Added the option to put "auto" in the latitude and longitude section of the theme, and if set, will query an api to get your location with your ip address. Implements caching and a backup api call if the first does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea, I like it!
I checked out the branch but unfortuantely it did not work for me. I set both long/lat config to auto
.
I see in the /tmp/.weather_location_cache
the following:
set -x
exec 2>/tmp/tmux-powerline.log
<code to debug>
set +x
Then I inserted these set -x
debug commands around the call to the function get_auto_location()
to see the execution of this function:
++ get_auto_location
++ local cache_file=/tmp/.weather_location_cache
++ local max_cache_age=86400
++ [[ -f /tmp/.weather_location_cache ]]
++ local location_data
++ apis=("https://ipapi.co/json" "https://ipinfo.io/json")
++ local -a apis
++ for api in "${apis[@]}"
+++ curl --max-time 4 -s https://ipapi.co/json
++ location_data='{
"error": true,
"reason": "RateLimited",
"message": "Visit https://ipapi.co/ratelimited/ for details"
}'
++ case "$api" in
+++ echo '{
"error": true,
"reason": "RateLimited",
"message": "Visit https://ipapi.co/ratelimited/ for details"
}'
+++ jq -r .latitude
++ TMUX_POWERLINE_SEG_WEATHER_LAT=null
+++ echo '{
"error": true,
"reason": "RateLimited",
"message": "Visit https://ipapi.co/ratelimited/ for details"
}'
+++ jq -r .longitude
++ TMUX_POWERLINE_SEG_WEATHER_LON=null
++ [[ -n null ]]
++ [[ -n null ]]
+++ dirname /tmp/.weather_location_cache
++ mkdir -p /tmp
++ echo 'export TMUX_POWERLINE_SEG_WEATHER_LAT='''null''''
++ echo 'export TMUX_POWERLINE_SEG_WEATHER_LON='''null''''
++ return 0
++ set +x
jq: error (at :1): Cannot index number with string "properties"
parse error: Invalid numeric literal at line 1, column 8
jq: error (at :1): Cannot index number with string "properties"
parse error: Invalid numeric literal at line 1, column 8
Looks like ratelimiting. If I visit in my browser https://ipapi.co/json it works.
segments/weather.sh
Outdated
@@ -179,3 +184,48 @@ __read_tmp_file() { | |||
cat "${tmp_file}" | |||
exit | |||
} | |||
|
|||
get_auto_location() { | |||
local cache_file="${TMUX_POWERLINE_DIR_USER:-/tmp}/.weather_location_cache" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other segments $TMUX_POWERLINE_DIR_TEMPORARY
is used from
tmux-powerline/config/paths.sh
Line 6 in 07315f2
export TMUX_POWERLINE_DIR_TEMPORARY="${TMPDIR:-/tmp/tmux-powerline_${USER}}" |
Also removed the bash arrays to be more compatible with older versions of bash
Thank you for checking this out! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update. I tried it again and now it works for me, no more rate limiting :-)
Added the option to put "auto" in the latitude and longitude section of the theme, and if set, will query an api to get your location with your ip address.
Implements caching and a backup api call if the first does not work.