diff options
| author | Hsieh Chin Fan <typebrook@topo.tw> | 2023-02-04 08:33:47 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <typebrook@topo.tw> | 2023-02-04 08:33:47 +0800 |
| commit | 825c29b5e0740b27439003f21e1a1a74e563cfd5 (patch) | |
| tree | 97e398b856abe9571efeedbf17e81ccc80118952 /X11/eww/scripts/weather_info | |
| parent | 4496db3c021d735a324a28c46ce4a18f090270f5 (diff) | |
Add eww config from aditaya
Diffstat (limited to 'X11/eww/scripts/weather_info')
| -rwxr-xr-x | X11/eww/scripts/weather_info | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/X11/eww/scripts/weather_info b/X11/eww/scripts/weather_info new file mode 100755 index 0000000..6fee821 --- /dev/null +++ b/X11/eww/scripts/weather_info | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | ## Collect data | ||
| 4 | cache_dir="$HOME/.cache/eww/weather" | ||
| 5 | cache_weather_stat=${cache_dir}/weather-stat | ||
| 6 | cache_weather_degree=${cache_dir}/weather-degree | ||
| 7 | cache_weather_quote=${cache_dir}/weather-quote | ||
| 8 | cache_weather_hex=${cache_dir}/weather-hex | ||
| 9 | cache_weather_icon=${cache_dir}/weather-icon | ||
| 10 | |||
| 11 | ## Weather data | ||
| 12 | KEY="YOUR_KEY" | ||
| 13 | ID="CITY_ID" | ||
| 14 | UNIT="metric" # Available options : 'metric' or 'imperial' | ||
| 15 | |||
| 16 | ## Make cache dir | ||
| 17 | if [[ ! -d "$cache_dir" ]]; then | ||
| 18 | mkdir -p ${cache_dir} | ||
| 19 | fi | ||
| 20 | |||
| 21 | ## Get data | ||
| 22 | get_weather_data() { | ||
| 23 | weather=`curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID="$KEY"&id="$ID"&units="$UNIT""` | ||
| 24 | echo ${weather} | ||
| 25 | |||
| 26 | if [ ! -z "$weather" ]; then | ||
| 27 | weather_temp=`echo "$weather" | jq ".main.temp" | cut -d "." -f 1` | ||
| 28 | weather_icon_code=`echo "$weather" | jq -r ".weather[].icon" | head -1` | ||
| 29 | weather_description=`echo "$weather" | jq -r ".weather[].description" | head -1 | sed -e "s/\b\(.\)/\u\1/g"` | ||
| 30 | |||
| 31 | #Big long if statement of doom | ||
| 32 | if [ "$weather_icon_code" == "50d" ]; then | ||
| 33 | weather_icon=" " | ||
| 34 | weather_quote="Forecast says it's misty \nMake sure you don't get lost on your way..." | ||
| 35 | weather_hex="#84afdb" | ||
| 36 | elif [ "$weather_icon_code" == "50n" ]; then | ||
| 37 | weather_icon=" " | ||
| 38 | weather_quote="Forecast says it's a misty night \nDon't go anywhere tonight or you might get lost..." | ||
| 39 | weather_hex="#84afdb" | ||
| 40 | elif [ "$weather_icon_code" == "01d" ]; then | ||
| 41 | weather_icon=" " | ||
| 42 | weather_quote="It's a sunny day, gonna be fun! \nDon't go wandering all by yourself though..." | ||
| 43 | weather_hex="#ffd86b" | ||
| 44 | elif [ "$weather_icon_code" == "01n" ]; then | ||
| 45 | weather_icon=" " | ||
| 46 | weather_quote="It's a clear night \nYou might want to take a evening stroll to relax..." | ||
| 47 | weather_hex="#fcdcf6" | ||
| 48 | elif [ "$weather_icon_code" == "02d" ]; then | ||
| 49 | weather_icon=" " | ||
| 50 | weather_quote="It's cloudy, sort of gloomy \nYou'd better get a book to read..." | ||
| 51 | weather_hex="#adadff" | ||
| 52 | elif [ "$weather_icon_code" == "02n" ]; then | ||
| 53 | weather_icon=" " | ||
| 54 | weather_quote="It's a cloudy night \nHow about some hot chocolate and a warm bed?" | ||
| 55 | weather_hex="#adadff" | ||
| 56 | elif [ "$weather_icon_code" == "03d" ]; then | ||
| 57 | weather_icon=" " | ||
| 58 | weather_quote="It's cloudy, sort of gloomy \nYou'd better get a book to read..." | ||
| 59 | weather_hex="#adadff" | ||
| 60 | elif [ "$weather_icon_code" == "03n" ]; then | ||
| 61 | weather_icon=" " | ||
| 62 | weather_quote="It's a cloudy night \nHow about some hot chocolate and a warm bed?" | ||
| 63 | weather_hex="#adadff" | ||
| 64 | elif [ "$weather_icon_code" == "04d" ]; then | ||
| 65 | weather_icon=" " | ||
| 66 | weather_quote="It's cloudy, sort of gloomy \nYou'd better get a book to read..." | ||
| 67 | weather_hex="#adadff" | ||
| 68 | elif [ "$weather_icon_code" == "04n" ]; then | ||
| 69 | weather_icon=" " | ||
| 70 | weather_quote="It's a cloudy night \nHow about some hot chocolate and a warm bed?" | ||
| 71 | weather_hex="#adadff" | ||
| 72 | elif [ "$weather_icon_code" == "09d" ]; then | ||
| 73 | weather_icon=" " | ||
| 74 | weather_quote="It's rainy, it's a great day! \nGet some ramen and watch as the rain falls..." | ||
| 75 | weather_hex="#6b95ff" | ||
| 76 | elif [ "$weather_icon_code" == "09n" ]; then | ||
| 77 | weather_icon=" " | ||
| 78 | weather_quote=" It's gonna rain tonight it seems \nMake sure your clothes aren't still outside..." | ||
| 79 | weather_hex="#6b95ff" | ||
| 80 | elif [ "$weather_icon_code" == "10d" ]; then | ||
| 81 | weather_icon=" " | ||
| 82 | weather_quote="It's rainy, it's a great day! \nGet some ramen and watch as the rain falls..." | ||
| 83 | weather_hex="#6b95ff" | ||
| 84 | elif [ "$weather_icon_code" == "10n" ]; then | ||
| 85 | weather_icon=" " | ||
| 86 | weather_quote=" It's gonna rain tonight it seems \nMake sure your clothes aren't still outside..." | ||
| 87 | weather_hex="#6b95ff" | ||
| 88 | elif [ "$weather_icon_code" == "11d" ]; then | ||
| 89 | weather_icon="" | ||
| 90 | weather_quote="There's storm for forecast today \nMake sure you don't get blown away..." | ||
| 91 | weather_hex="#ffeb57" | ||
| 92 | elif [ "$weather_icon_code" == "11n" ]; then | ||
| 93 | weather_icon="" | ||
| 94 | weather_quote="There's gonna be storms tonight \nMake sure you're warm in bed and the windows are shut..." | ||
| 95 | weather_hex="#ffeb57" | ||
| 96 | elif [ "$weather_icon_code" == "13d" ]; then | ||
| 97 | weather_icon=" " | ||
| 98 | weather_quote="It's gonna snow today \nYou'd better wear thick clothes and make a snowman as well!" | ||
| 99 | weather_hex="#e3e6fc" | ||
| 100 | elif [ "$weather_icon_code" == "13n" ]; then | ||
| 101 | weather_icon=" " | ||
| 102 | weather_quote="It's gonna snow tonight \nMake sure you get up early tomorrow to see the sights..." | ||
| 103 | weather_hex="#e3e6fc" | ||
| 104 | elif [ "$weather_icon_code" == "40d" ]; then | ||
| 105 | weather_icon=" " | ||
| 106 | weather_quote="Forecast says it's misty \nMake sure you don't get lost on your way..." | ||
| 107 | weather_hex="#84afdb" | ||
| 108 | elif [ "$weather_icon_code" == "40n" ]; then | ||
| 109 | weather_icon=" " | ||
| 110 | weather_quote="Forecast says it's a misty night \nDon't go anywhere tonight or you might get lost..." | ||
| 111 | weather_hex="#84afdb" | ||
| 112 | else | ||
| 113 | weather_icon=" " | ||
| 114 | weather_quote="Sort of odd, I don't know what to forecast \nMake sure you have a good time!" | ||
| 115 | weather_hex="#adadff" | ||
| 116 | fi | ||
| 117 | echo "$weather_icon" > ${cache_weather_icon} | ||
| 118 | echo "$weather_description" > ${cache_weather_stat} | ||
| 119 | echo "$weather_temp""°C" > ${cache_weather_degree} | ||
| 120 | echo -e "$weather_quote" > ${cache_weather_quote} | ||
| 121 | echo "$weather_hex" > ${cache_weather_hex} | ||
| 122 | else | ||
| 123 | echo "Weather Unavailable" > ${cache_weather_stat} | ||
| 124 | echo " " > ${cache_weather_icon} | ||
| 125 | echo -e "Ah well, no weather huh? \nEven if there's no weather, it's gonna be a great day!" > ${cache_weather_quote} | ||
| 126 | echo "-" > ${cache_weather_degree} | ||
| 127 | echo "#adadff" > ${tcache_weather_hex} | ||
| 128 | fi | ||
| 129 | } | ||
| 130 | |||
| 131 | ## Execute | ||
| 132 | if [[ "$1" == "--getdata" ]]; then | ||
| 133 | get_weather_data | ||
| 134 | elif [[ "$1" == "--icon" ]]; then | ||
| 135 | cat ${cache_weather_icon} | ||
| 136 | elif [[ "$1" == "--temp" ]]; then | ||
| 137 | cat ${cache_weather_degree} | ||
| 138 | elif [[ "$1" == "--hex" ]]; then | ||
| 139 | cat ${cache_weather_hex} | ||
| 140 | elif [[ "$1" == "--stat" ]]; then | ||
| 141 | cat ${cache_weather_stat} | ||
| 142 | elif [[ "$1" == "--quote" ]]; then | ||
| 143 | cat ${cache_weather_quote} | head -n1 | ||
| 144 | elif [[ "$1" == "--quote2" ]]; then | ||
| 145 | cat ${cache_weather_quote} | tail -n1 | ||
| 146 | fi | ||
| 147 | |||