summaryrefslogtreecommitdiff
path: root/mac/.config/sketchybar.mon/sketchybar/plugins/weather.sh
diff options
context:
space:
mode:
Diffstat (limited to 'mac/.config/sketchybar.mon/sketchybar/plugins/weather.sh')
-rwxr-xr-xmac/.config/sketchybar.mon/sketchybar/plugins/weather.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/mac/.config/sketchybar.mon/sketchybar/plugins/weather.sh b/mac/.config/sketchybar.mon/sketchybar/plugins/weather.sh
new file mode 100755
index 0000000..b96bab8
--- /dev/null
+++ b/mac/.config/sketchybar.mon/sketchybar/plugins/weather.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+# Source colors for consistent theming
+source "$CONFIG_DIR/colors.sh"
+
+# Cache file for weather data
+CACHE_FILE="/tmp/sketchybar_weather_cache"
+CACHE_DURATION=1800 # 30 minutes
+
+# Function to get weather data
+get_weather() {
+ # You can replace this with your preferred weather API
+ # For now, using a simple placeholder
+ local location="San Francisco" # Change to your location
+
+ # Try to get weather from wttr.in (simple text-based weather)
+ local weather_data=$(curl -s "wttr.in/$location?format=3" 2>/dev/null)
+
+ if [ -n "$weather_data" ]; then
+ echo "$weather_data"
+ else
+ echo "Weather unavailable"
+ fi
+}
+
+# Check if cache is valid
+if [ -f "$CACHE_FILE" ]; then
+ cache_time=$(stat -f %m "$CACHE_FILE" 2>/dev/null || echo 0)
+ current_time=$(date +%s)
+
+ if [ $((current_time - cache_time)) -lt $CACHE_DURATION ]; then
+ weather=$(cat "$CACHE_FILE")
+ else
+ weather=$(get_weather)
+ echo "$weather" > "$CACHE_FILE"
+ fi
+else
+ weather=$(get_weather)
+ echo "$weather" > "$CACHE_FILE"
+fi
+
+# Extract temperature and condition
+if [[ "$weather" =~ ([0-9.-]+°[CF]) ]]; then
+ temp="${BASH_REMATCH[1]}"
+ sketchybar --set "$NAME" label="$temp" \
+ icon.color=$BLUE \
+ label.color=$WHITE
+else
+ sketchybar --set "$NAME" label="N/A" \
+ icon.color=$GREY \
+ label.color=$GREY
+fi