aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/UserScripts
diff options
context:
space:
mode:
Diffstat (limited to 'config/hypr/UserScripts')
-rwxr-xr-xconfig/hypr/UserScripts/Weather.sh46
1 files changed, 40 insertions, 6 deletions
diff --git a/config/hypr/UserScripts/Weather.sh b/config/hypr/UserScripts/Weather.sh
index ac9abc13..4588ed1d 100755
--- a/config/hypr/UserScripts/Weather.sh
+++ b/config/hypr/UserScripts/Weather.sh
@@ -2,16 +2,50 @@
# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
# weather info from wttr. https://github.com/chubin/wttr.in
# Remember to add city
+# Function to get current city from IP address with fallback
-city=""
+# Get your current location with your IP adress
+get_current_city() {
+ local city
+
+ # First try: ipinfo.io
+ local location_data=$(curl -fsS "https://ipinfo.io/json" 2>/dev/null)
+ if [ $? -eq 0 ] && [ -n "$location_data" ]; then
+ city=$(echo "$location_data" | grep -o '"city"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
+ if [ -n "$city" ]; then
+ echo "$city"
+ return 0
+ fi
+ fi
+
+ # Fallback: ipapi.co
+ city=$(curl -fsS "https://ipapi.co/json" 2>/dev/null | grep -o '"city"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
+ if [ -n "$city" ]; then
+ echo "$city"
+ return 0
+ fi
+
+ # Last resort: ipwho.is
+ city=$(curl -fsS "https://ipwho.is/" 2>/dev/null | grep -o '"city"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
+ if [ -n "$city" ]; then
+ echo "$city"
+ return 0
+ fi
+
+ # If all fail
+ echo "Unknown" >&2
+ return 1
+}
+city=$(get_current_city)
-# if city is blank, use https://ipapi.co/json to get location from IP
-if [ -z "$city" ]; then
- city=$(curl -fsS https://ipapi.co/json | grep city | cut -f4 -d'"')
+# If city is empty, that means the IP check failed, which means, we should use manual setting
+if [ -z "$city" ] || [ "$city" = "Unknown" ]; then
+ # SET YOUR MANUAL CITY HERE
+ city=" " # ← Change this to your preferred city
+ echo "Using manual city: $city" >&2
fi
-
# URL-encode city for safe use in URLs
encoded_city="$city"
if command -v python3 >/dev/null 2>&1; then
@@ -206,4 +240,4 @@ tooltip_json=$(json_escape "${weather[0]}: $temperature $cond_disp")
printf '{"text":"%s", "alt":"%s", "tooltip":"%s"}\n' "$text_json" "$alt_json" "$tooltip_json"
# Write a two-line cache with an actual newline between lines
-printf ' %s \n%s %s\n' "$temperature" "$condition" "${weather[1]}" > "$HOME/.cache/.weather_cache" \ No newline at end of file
+printf ' %s \n%s %s\n' "$temperature" "$condition" "${weather[1]}" > "$HOME/.cache/.weather_cache"
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage