Last active
September 23, 2016 20:35
-
-
Save dersam/eeaaac2a1209e8dd2f42f4b4a0c3cd6e to your computer and use it in GitHub Desktop.
Revisions
-
dersam revised this gist
Sep 23, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ CITY=$(echo "$LOCATION" | cut -d , -f 6) LAT=$(echo "$LOCATION" | cut -d , -f 8) LON=$(echo "$LOCATION" | cut -d , -f 9) WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&APPID="$WEATHER_API_KEY"\&units=metric) CATEGORY=$(echo "$WEATHER" | jq .weather[0].id) TEMP="$(echo "$WEATHER" | jq .main.temp | cut -d . -f 1)°C" -
dersam created this gist
Sep 23, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ # Weather # ======= # # By Jezen Thomas <[email protected]> # # This script sends a couple of requests over the network to retrieve # approximate location data, and the current weather for that location. This is # useful if for example you want to display the current weather in your tmux # status bar. # There are three things you will need to do before using this script. # # 1. Install jq with your package manager of choice (homebrew, apt-get, etc.) # 2. Sign up for a free account with OpenWeatherMap to grab your API key # 3. Add your OpenWeatherMap API key where it says API_KEY set -e # Not all icons for weather symbols have been added yet. If the weather # category is not matched in this case statement, the command output will # include the category ID. You can add the appropriate emoji as you go along. # # Weather data reference: http://openweathermap.org/weather-conditions weather_icon() { case $1 in 500) echo 🌦 ;; 800) echo ☀️ ;; 801) echo 🌤 ;; 803) echo ⛅️ ;; 804) echo ☁️ ;; *) echo "$1" esac } LOCATION=$(curl --silent http://ip-api.com/csv) CITY=$(echo "$LOCATION" | cut -d , -f 6) LAT=$(echo "$LOCATION" | cut -d , -f 8) LON=$(echo "$LOCATION" | cut -d , -f 9) WEATHER=$(curl --silent http://api.openweathermap.org/data/2.5/weather\?lat="$LAT"\&lon="$LON"\&APPID="$API_KEY"\&units=metric) CATEGORY=$(echo "$WEATHER" | jq .weather[0].id) TEMP="$(echo "$WEATHER" | jq .main.temp | cut -d . -f 1)°C" WIND_SPEED="$(echo "$WEATHER" | jq .wind.speed | awk '{print int($1+0.5)}')ms" ICON=$(weather_icon "$CATEGORY") printf "%s" "$CITY:$ICON $TEMP, $WIND_SPEED"