1st dotfiles commit

This commit is contained in:
ohinh 2026-08-03 17:03:40 +02:00
parent 39c99549d0
commit a57c4c068f
31 changed files with 8636 additions and 0 deletions

59
waybar/scripts/weather.sh Executable file
View file

@ -0,0 +1,59 @@
#!/bin/bash
# --- CONFIGURATION ---
API_KEY="00e744eb427e575e1e8ed79f31f770fb" # Paste your key here
LAT="48.856613" # Replace with your Latitude
LON="2.352222" # Replace with your Longitude
UNITS="metric" # Use "metric" for Celsius, "imperial" for Fahrenheit
# ---------------------
# Validate configuration
if [ -z "$LAT" ] || [ -z "$LON" ] || [ -z "$UNITS" ] || [ -z "$API_KEY" ]; then
echo "Config missing"
exit 1
fi
# Fetch the weather data
RESPONSE=$(curl -s "[https://api.openweathermap.org/data/2.5/weather?lat=$](https://api.openweathermap.org/data/2.5/weather?lat=$){LAT}&lon=${LON}&appid=${API_KEY}&units=${UNITS}")
# Check if curl failed to get a response
if [ -z "$RESPONSE" ]; then
echo "No connection"
exit 1
fi
# 1. Get the Temperature
# We use jq's built-in 'round' function to avoid ugly decimals (e.g., 71.6°F becomes 72°F)
TEMP=$(echo "$RESPONSE" | jq '.main.temp | round')
# 2. Get the Description (for the tooltip)
DESC=$(echo "$RESPONSE" | jq -r '.weather[0].description')
# 3. Get the Icon Code and map it to an emoji
ICON_CODE=$(echo "$RESPONSE" | jq -r '.weather[0].icon')
case $ICON_CODE in
"01d") ICON="☀️";; # Clear sky day
"01n") ICON="🌙";; # Clear sky night
"02d") ICON="⛅";; # Few clouds day
"02n") ICON="☁️";; # Few clouds night
"03d"|"03n") ICON="☁️";; # Scattered clouds
"04d"|"04n") ICON="☁️";; # Broken clouds
"09d"|"09n") ICON="🌧️";; # Shower rain
"10d") ICON="🌦️";; # Rain day
"10n") ICON="🌧️";; # Rain night
"11d"|"11n") ICON="⛈️";; # Thunderstorm
"13d"|"13n") ICON="❄️";; # Snow
"50d"|"50n") ICON="🌫️";; # Mist
*) ICON="❓";; # Default
esac
# Determine unit label
if [ "$UNITS" = "metric" ]; then
LABEL="°C"
else
LABEL="°F"
fi
# Final JSON output for Waybar
echo "{\"text\": \"${ICON} ${TEMP}${LABEL}\", \"tooltip\": \"${DESC}\"}"

View file

@ -0,0 +1,83 @@
#!/usr/bin/env python3
import requests
import json
import sys
import os
# CONFIGURATION
import requests
import json
import sys
import os
# CONFIGURATION
API_KEY = "ebb6d6ea53be021675e3276f7fe8cd77" # Remplacez par votre clé OpenWeatherMap
CITY = "Paris" # Ville par défaut si non précisée
UNITS = "metric" # "metric" pour °C, "imperial" pour °F
LANG = "fr" # "fr" pour français, "en" pour anglais
def get_weather():
if not API_KEY or API_KEY == "VOTRE_CLE_API_ICI":
return {"text": "❌ Clé API manquante", "class": "weather-error", "tooltip": "Configurez la clé API dans le script."}
try:
url = f"https://api.openweathermap.org/data/2.5/weather?q={CITY}&appid={API_KEY}&units={UNITS}&lang={LANG}"
response = requests.get(url, timeout=5)
if response.status_code == 401:
return {"text": "❌ Clé API invalide", "class": "weather-error", "tooltip": "Erreur 401: Vérifiez votre clé OpenWeatherMap."}
if response.status_code == 404:
return {"text": "❌ Ville introuvable", "class": "weather-error", "tooltip": f"La ville '{CITY}' n'a pas été trouvée."}
if response.status_code != 200:
return {"text": "⚠️ Erreur API", "class": "weather-error", "tooltip": f"Code {response.status_code}: {response.text}"}
data = response.json()
# Extraction des données
temp = data["main"]["temp"]
description = data["weather"][0]["description"].capitalize()
icon_code = data["weather"][0]["icon"]
wind_speed = data["wind"]["speed"]
# Mapping des icônes OpenWeather vers les icônes Waybar standard (ou Unicode)
# OpenWeather utilise des codes comme "10d", "01n". Waybar utilise souvent des noms ou des emojis.
# Ici, nous utilisons des emojis pour une compatibilité universelle.
icon = "☁️"
if "01" in icon_code:
icon = "☀️" if "d" in icon_code else "🌙"
elif "02" in icon_code:
icon = "" if "d" in icon_code else "🌥️"
elif "03" in icon_code or "04" in icon_code:
icon = "☁️"
elif "09" in icon_code or "10" in icon_code:
icon = "🌧️"
elif "11" in icon_code:
icon = "⛈️"
elif "13" in icon_code:
icon = "❄️"
elif "50" in icon_code:
icon = "🌫️"
# Formatage du texte
text = f"{icon} {int(temp)}°C"
tooltip = f"{description}\nVent: {wind_speed} m/s\nVille: {data['name']}, {data['sys']['country']}"
return {
"text": text,
"tooltip": tooltip,
"class": "weather-good" if temp > 10 else "weather-cold" if temp < 0 else "weather-warm"
}
except requests.exceptions.Timeout:
return {"text": "⏱️ Timeout", "class": "weather-error", "tooltip": "La requête a expiré."}
except requests.exceptions.ConnectionError:
return {"text": "🚫 Pas de réseau", "class": "weather-error", "tooltip": "Impossible de se connecter à OpenWeatherMap."}
except Exception as e:
return {"text": "❌ Erreur", "class": "weather-error", "tooltip": str(e)}
if __name__ == "__main__":
result = get_weather()
print(json.dumps(result))
sys.stdout.flush()