pax_global_header00006660000000000000000000000064126146763750014533gustar00rootroot0000000000000052 comment=eaecfb515784733082a50ca78dff2481e9d2985a ansiweather-1.06/000077500000000000000000000000001261467637500137735ustar00rootroot00000000000000ansiweather-1.06/AUTHORS000066400000000000000000000002161261467637500150420ustar00rootroot00000000000000AnsiWeather is developed by : Frederic Cambus Site : http://www.cambus.net Twitter : @fcambus ansiweather-1.06/ChangeLog000066400000000000000000000043251261467637500155510ustar00rootroot00000000000000AnsiWeather 1.06 (2015-10-30) - Added support for OpenWeatherMap API keys - Changed curl options from '-s' to '-sf' to fail silently on server errors - Removing auto location helper, user location must now be explicitly set - Changed default city to Rzeszow, Poland - Changing rain and thunderstorm icons default colors to white and yellow - Documentation updates AnsiWeather 1.05 (2015-09-27) - Fixes for numeric translation on NetBSD (Thanks Kamil Rytarowski) - Use xargs printf construct to avoid hardcoding path to external printf command (Thanks Kamil Rytarowski) - Use '/bin/sh' shebang instead of '/usr/bin/env sh' for portability reasons (Thanks Kamil Rytarowski) - Replacing spaces by underscores in location name before calling the weather API - Force bc to always return integers for wind directions (Thanks Lornix) - Documentation updates AnsiWeather 1.04 (2015-09-10) - Added a '-a' option to toggle ANSI colors display - Daylight option in the example configuration file now default to false to match program default - Better formatting for usage display - Documentation updates AnsiWeather 1.03 (2015-09-08) - Removed dependency on Bash, AnsiWeather is now using plain sh - Detect all numeric locations and switching from 'q' to 'id' API query parameter in this case - Do not attempt to convert pressure data to imperial units in forecast mode (Bugfix) - Added a '-h' option to display usage - Parse arguments before setting options (Thanks Lucas Hoffmann) - Documentation updates - Linting and minor fixes AnsiWeather 1.02 (2015-05-09) - Documentation updates - Populated ChangeLog - Allow overriding default config file location using ANSIWEATHERRC environment varibale (Thanks Lucas Hoffmann) - Check if 'bc' is installed before starting AnsiWeather 1.01 (2015-03-16) - Add ability to store options in config file (Thanks Aaron Bieber) - Automatic location detection (Thanks Michael Price) - Showing wind direction and speed - Add ability to display upcoming weekly forecast (Thanks Michael Reinhardt) - Add ability to display daylight data (Thanks Roy Hodgman) - Allow custom geolocation server to be set (Thanks Aaron Bieber) - Removed dependency on seq AnsiWeather 1.00 (2013-10-19) - Initial release ansiweather-1.06/LICENSE000066400000000000000000000027301261467637500150020ustar00rootroot00000000000000Copyright (c) 2013-2015, Frederic Cambus All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of AnsiWeather nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ansiweather-1.06/README.md000066400000000000000000000110121261467637500152450ustar00rootroot00000000000000## Description AnsiWeather is a Shell script for displaying the current weather conditions in your terminal, with support for ANSI colors and Unicode symbols. ![AnsiWeather Screenshot](http://www.cambus.net/content/2013/10/ansiweather.png) Weather data comes from the `OpenWeatherMap` free weather API. ## Requirements AnsiWeather requires the following dependencies : - A command to fetch HTTP data such as FTP, [cURL](http://curl.haxx.se) or [wget](https://www.gnu.org/software/wget/) - [jq](http://stedolan.github.io/jq/) (lightweight and flexible command-line JSON processor) - [bc](https://www.gnu.org/software/bc/) (arbitrary precision numeric processing language), for doing float arithmetic ## Installation After cloning the repository, simply invoke the script by typing : ./ansiweather AnsiWeather packages are available for : ### OpenBSD pkg_add ansiweather ### Pkgsrc (NetBSD, SmartOS, Mac OS X, etc.) pkgin install ansiweather ### FreeBSD pkg install ansiweather ### Debian apt-get install ansiweather ### Homebrew (Mac OS X) brew install ansiweather ## Usage ansiweather [options] Options are : -l Specify location -u Specify unit system to use (metric or imperial) -f Toggle forecast mode for the specified number of upcoming days -F Toggle forecast mode for the next five days -d Toggle daylight data display -a Toggle ANSI colors display -s Toggle symbols display -k API key -h Display usage ## Command Line Options Any configuration options may also be passed in as command line options : ansiweather -l Rzeszow,PL -u metric -s true -f 5 -d true ## Configuration The default config file is ~/.ansiweatherrc. The environment variable ANSIWEATHERRC can be set to override this. The following configuration options (detailed below) are available and should be set according to your location and preferences. Example : `~/.ansiweatherrc` location:Rzeszow,PL fetch_cmd:ftp -V -o - units:metric daylight:true The file `ansiweatherrc.example` contains all available configuration variables. ### Location Location format is `city,CC` where `CC` is a two-letter ISO 3166-1 alpha-2 country code. A list of country codes is available [here](http://www.statdns.com/cctlds/). Alternatively, it's also possible to specify locations by their ID, a city list is available [here](http://openweathermap.org/help/city_list.txt). In case no location is specified, AnsiWeather will fallback to the default location. Example : `Rzeszow,PL` location:Rzeszow,PL ### Fetch Command Various tools can be used to fetch data : `curl`, `wget`, `ftp`. Please note that `ftp` flags and options might differ among implementations and versions, and the example provided here is known to work only on OpenBSD, NetBSD and Mac OS X. Example : `curl -sf` fetch_cmd:curl -sf Example : `wget -qO-` fetch_cmd:wget -qO- Example : `ftp -V -o -` fetch_cmd:ftp -V -o - Default: `curl -sf` ### System of Units Both `metric` and `imperial` systems are supported. units:metric Default: `metric` ### Display ANSI sequences Toggle ANSI sequences display. Value can be either `true` (requires an ANSI capable display) or `false`. ansi:true Default: `true` ### Display symbols Toggle Unicode symbols display. Value can be either `true` (requires an Unicode capable display) or `false`. symbols:true Default: `true` Symbols can be configured or replaced by custom text using the following configuration variables : `sun`, `moon`, `clouds`, `rain`, `fog`, `mist`, `haze`, `snow`, `thunderstorm`. ### Display forecast Show upcoming forecast for the next `N` days (for 0 <= N <= 7). `0` will show standard output. forecast:5 Default: `0` ### Display sunrise / sunset Toggle daylight display. Value can be either `true` or `false`. daylight:false Default: `false` ### Date and Time format Configure date and time format display. See Unix date formatting documentation for details. dateformat:%a %b %d Default : `%a %b %d` timeformat:%b %d %r Default : `%b %d %r` ### OpenWeatherMap API key Specify an OpenWeatherMap API key. By default AnsiWeather uses its own key, but users can optionally get their own one by creating a free [OpenWeatherMap account](http://home.openweathermap.org/users/sign_up). api_key:85a4e3c55b73909f42c6a23ec35b7147 ## License AnsiWeather is released under the BSD 3-Clause license. See `LICENSE` file for details. ## Author AnsiWeather is developed by Frederic Cambus - Site : http://www.cambus.net - Twitter: http://twitter.com/fcambus ## Resources GitHub : https://github.com/fcambus/ansiweather ansiweather-1.06/ansiweather000077500000000000000000000237661261467637500162510ustar00rootroot00000000000000#!/bin/sh ############################################################################### # # # AnsiWeather 1.06 (c) by Frederic Cambus 2013-2015 # # https://github.com/fcambus/ansiweather # # # # Created: 2013/08/29 # # Last Updated: 2015/10/30 # # # # AnsiWeather is released under the BSD 3-Clause license. # # See LICENSE file for details. # # # ############################################################################### ###[ Configuration options ]################################################### LC_ALL=C; export LC_ALL config_file=${ANSIWEATHERRC:-~/.ansiweatherrc} get_config() { ret="" if [ -f "$config_file" ] then ret=$(grep "^$1:" "$config_file" | awk -F: '{print $2}') fi if [ "X$ret" = "X" ] then return 1 else echo "$ret" fi } fetch_cmd=$(get_config "fetch_cmd" || echo "curl -sf") ###[ Parse the command line ]################################################## # Get config options from command line flags while getopts k:l:u:f:Fd:a:s:h option do case "${option}" in l) location=${OPTARG};; u) units=${OPTARG};; f) forecast=${OPTARG};; F) forecast="5";; d) daylight=${OPTARG};; a) ansi=${OPTARG};; s) symbols=${OPTARG};; k) api_key=${OPTARG};; h) usage=true;; esac done ###[ Display usage ]########################################################### if [ "$usage" = true ] then printf "%s\n" \ "" \ "AnsiWeather 1.06 (c) by Frederic Cambus 2013-2015" \ "" \ "USAGE: ansiweather [options]" \ "" \ "Options are :" \ "" \ " -l Specify location" \ " -u Specify unit system to use (metric or imperial)" \ " -f Toggle forecast mode for the specified number of upcoming days" \ " -F Toggle forecast mode for the next five days" \ " -d Toggle daylight data display" \ " -a Toggle ANSI colors display" \ " -s Toggle symbols display" \ " -k OpenWeatherMap API key" \ " -h Display usage" \ "" \ "EXAMPLES: ansiweather -l Moscow,RU -u metric -s true -f 5 -d true" \ "" exit fi ###[ Check if bc and jq are installed ]######################################## jqpath=$(which jq) if [ "$jqpath" = "" ] then echo "ERROR : Cannot find jq binary" exit fi bcpath=$(which bc) if [ "$bcpath" = "" ] then echo "ERROR : Cannot find bc binary" exit fi ###[ Set options that are not set from command line ]########################## # OpenWeatherMap API key [ -z "$api_key" ] && api_key=$(get_config "api_key" || echo "85a4e3c55b73909f42c6a23ec35b7147") # Location : example "Moscow,RU" [ -z "$location" ] && location=$(get_config "location" || echo "Rzeszow,PL") # System of Units : "metric" or "imperial" [ -z "$units" ] && units=$(get_config "units" || echo "metric") # Show forecast : How many days, example "5". "0" is standard output [ -z "$forecast" ] && forecast=$(get_config "forecast" || echo 0) # Show daylight : "true" or "false" [ -z "$daylight" ] && daylight=$(get_config "daylight" || echo false) # Display ANSI colors : "true" or "false" [ -z "$ansi" ] && ansi=$(get_config "ansi" || echo true) # Display symbols : "true" or "false" (requires an Unicode capable display) [ -z "$symbols" ] && symbols=$(get_config "symbols" || echo true) dateformat=$(get_config "dateformat" || echo "%a %b %d") timeformat=$(get_config "timeformat" || echo "%b %d %r") ###[ Colors and characters ]################################################### background=$(get_config "background" || echo "\033[44m") text=$(get_config "text" || echo "\033[36;1m") data=$(get_config "data" || echo "\033[33;1m") delimiter=$(get_config "delimiter" || echo "\033[35m=>") dashes=$(get_config "dashes" || echo "\033[34m-") ###[ Text Labels ]############################################################# greeting_text=$(get_config "greeting_text" || echo "Current weather in") wind_text=$(get_config "wind_text" || echo "Wind") humidity_text=$(get_config "humidity_text" || echo "Humidity") pressure_text=$(get_config "pressure_text" || echo "Pressure") sunrise_text=$(get_config "sunrise_text" || echo "Sunrise") sunset_text=$(get_config "sunset_text" || echo "Sunset") ###[ Unicode Symbols for icons ]############################################### sun=$(get_config "sun" || echo "\033[33;1m\xe2\x98\x80") moon=$(get_config "moon" || echo "\033[36m\xe2\x98\xbd") clouds=$(get_config "clouds" || echo "\033[37;1m\xe2\x98\x81") rain=$(get_config "rain" || echo "\033[37;1m\xe2\x98\x94") fog=$(get_config "fog" || echo "\033[37;1m\xe2\x96\x92") mist=$(get_config "mist" || echo "\033[34m\xe2\x96\x91") haze=$(get_config "haze" || echo "\033[33m\xe2\x96\x91") snow=$(get_config "snow" || echo "\033[37;1m\xe2\x9d\x84") thunderstorm=$(get_config "thunderstorm" || echo "\033[33;1m\xe2\x9a\xa1") ###[ Fetch Weather data ]###################################################### api_cmd=$([ "$forecast" != 0 ] && echo "forecast/daily" || echo "weather") if [ "$location" -gt 0 ] 2> /dev/null then # Location is all numeric weather=$($fetch_cmd "http://api.openweathermap.org/data/2.5/$api_cmd?id=$location&units=$units&appid=$api_key") else # Location is a string location=$(echo "$location" | sed "s/ /_/g") weather=$($fetch_cmd "http://api.openweathermap.org/data/2.5/$api_cmd?q=$location&units=$units&appid=$api_key") fi if [ -z "$weather" ] then echo "ERROR : Cannot fetch weather data" exit fi status_code=$(echo "$weather" | jq -r '.cod' 2>/dev/null) if [ "$status_code" != 200 ] then echo "ERROR : Cannot fetch weather data for the given location" exit fi ###[ Process Weather data ]#################################################### epoch_to_date() { if date -j -r "$1" +"%a %b %d" > /dev/null 2>&1; then # BSD ret=$(date -j -r "$1" +"$dateformat") else # GNU ret=$(date -d "@$1" +"$dateformat") fi echo "$ret" } if [ "$forecast" != 0 ] then city=$(echo "$weather" | jq -r '.city.name') flength=$(echo "$weather" | jq '.list | length') forecast=$([ "$forecast" -gt "$flength" ] && echo "$flength" || echo "$forecast") else city=$(echo "$weather" | jq -r '.name') temperature=$(echo "$weather" | jq '.main.temp' | xargs printf "%.0f") humidity=$(echo "$weather" | jq '.main.humidity') pressure=$(echo "$weather" | jq '.main.pressure') sky=$(echo "$weather" | jq -r '.weather[0].main') sunrise=$(echo "$weather" | jq '.sys.sunrise') sunset=$(echo "$weather" | jq '.sys.sunset') wind=$(echo "$weather" | jq '.wind.speed') azimuth=$(echo "$weather" | jq '.wind.deg') fi ###[ Process Wind data ]####################################################### set -- N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW if [ "$forecast" = 0 ] then shift "$(echo "scale=0; ($azimuth + 11.25)/22.5 % 16" | bc)" direction=$1 fi ###[ Process Sunrise and Sunset data ]######################################### epoch_to_time() { if date -j -r "$1" +"%r" > /dev/null 2>&1; then # BSD ret=$(date -j -r "$1" +"$timeformat") else # GNU ret=$(date -d "@$1" +"$timeformat") fi echo "$ret" } if [ "$forecast" = 0 ] then if [ -n "$sunrise" ] then sunrise_time=$(epoch_to_time "$sunrise") fi if [ -n "$sunset" ] then sunset_time=$(epoch_to_time "$sunset") fi fi ###[ Set the period ]########################################################## now=$(date +%s) if [ "$forecast" != 0 ] then period="none" else if [ -z "$sunset" ] || [ -z "$sunrise" ] then period="day" elif [ "$now" -ge "$sunset" ] || [ "$now" -le "$sunrise" ] then period="night" else period="day" fi fi ###[ Set the scale ]########################################################### case $units in metric) scale="°C" speed_unit="m/s" pressure_unit="hPa" pressure=$(echo "$pressure" | xargs printf "%.0f") ;; imperial) scale="°F" speed_unit="mph" pressure_unit="inHg" if [ "$forecast" = 0 ] then pressure=$(echo "$pressure*0.0295" | bc | xargs printf "%.2f") fi ;; esac ###[ Set icons ]############################################################### get_icon() { case $1 in Clear) if [ $period = "night" ] then echo "$moon " else echo "$sun " fi ;; Clouds) echo "$clouds " ;; Rain) echo "$rain " ;; Fog) echo "$fog " ;; Mist) echo "$mist " ;; Haze) echo "$haze " ;; Snow) echo "$snow " ;; Thunderstorm) echo "$thunderstorm " ;; esac } ###[ Display current Weather ]################################################# if [ "$forecast" != 0 ] then output="$background$text $city forecast $text$delimiter " i=0 while [ $i -lt "$forecast" ] do day=$(echo "$weather" | jq ".list[$i]") date=$(epoch_to_date "$(echo "$day" | jq -r '.dt')") low=$(echo "$day" | jq -r '.temp.min' | xargs printf "%.0f") high=$(echo "$day" | jq -r '.temp.max' | xargs printf "%.0f") icon="" if [ "$symbols" = true ] then sky=$(echo "$day" | jq -r '.weather[0].main') icon=$(get_icon "$sky") fi output="$output$text$date: $data$high$text/$data$low $scale $icon" if [ $i -lt $((forecast-1)) ] then output="$output$dashes " fi i=$((i + 1)) done else if [ "$symbols" = true ] then icon="$(get_icon "$sky")" fi output="$background$text $greeting_text $city $delimiter$data $temperature $scale $icon$dashes$text $wind_text $delimiter$data $wind $speed_unit $direction $dashes$text $humidity_text $delimiter$data $humidity %% $dashes$text $pressure_text $delimiter$data $pressure $pressure_unit " if [ "$daylight" = true ] then output="$output $dashes$text $sunrise_text $delimiter$data $sunrise_time $dashes$text $sunset_text $delimiter$data $sunset_time " fi fi if [ "$ansi" = true ] then /usr/bin/printf "$output\033[0m\n" else /usr/bin/printf "$output\n" | sed "s/$(printf '\033')\[[0-9;]*m//g" fi ansiweather-1.06/ansiweather.plugin.zsh000077500000000000000000000000421261467637500203270ustar00rootroot00000000000000export PATH=${PATH}:$(dirname $0) ansiweather-1.06/ansiweatherrc.example000066400000000000000000000013501261467637500202060ustar00rootroot00000000000000# .ansiweatherrc example showing all available options api_key:85a4e3c55b73909f42c6a23ec35b7147 fetch_cmd:curl -sf location:Rzeszow,PL units:metric forecast:0 daylight:false ansi:true symbols:true dateformat:%a %b %d timeformat:%b %d %r # Text and Colors background:\033[44m text:\033[36;1m data:\033[33;1m delimiter:\033[35m=> dashes:\033[34m- greeting_text:Current weather in wind_text:Wind humidity_text:Humidity pressure_text:Pressure sunrise_text:Sunrise sunset_text:Sunset # Icons sun:\033[33;1m\xe2\x98\x80 moon:\033[36m\xe2\x98\xbd clouds:\033[37;1m\xe2\x98\x81 rain:\033[37;1m\xe2\x98\x94 fog:\033[37;1m\xe2\x96\x92 mist:\033[34m\xe2\x96\x91 haze:\033[33m\xe2\x96\x91 snow:\033[37;1m\xe2\x9d\x84 thunderstorm:\033[33;1m\xe2\x9a\xa1