Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 51 lines (43 sloc) 2.23 KB
#!/bin/bash
# Description
# -----------
# <img src="https://developer.run/pic/wa_full.png"/>
# <img src="https://developer.run/pic/wa.png"/>
# <img src="https://developer.run/pic/wa2.png"/>
#
# Using Wolfram Alpha in command line. See <http://developer.run/37> for description and more ideas.
# Author: [Dmitry](http://dmi3.net) [Source](https://github.com/dmi3/bin)
# Requirements
# ------------
# You can use text only api and **optionaly** use [terminal that supports images](https://sw.kovidgoyal.net/kitty/)
# **or** `sudo apt-get install imagemagick` to view images
# Usage
# ------------
# ➤ wa helsinki to dublin plane
# 2 hours 20 minutes
# ➤ wa time in dublin
# 5:37:57 pm GMT; Friday, January 27, 2017
# ➤ wa 15.36 english money to eur
# 14.35 euros
# ➤ wa days till nov 16
# 293 days
# ➤ wa 154Mbit/s to MB/s
# 19.2 megabytes per second
# ➤ wa brick red hex
# #AB0303
# ➤ wa weather in moscow
# 9 degrees Celsius and cloudy, with light winds✖
# ➤ wa plot x=y^2
# [...draws plot if supported]
# ➤ # many many more usages... https://www.wolframalpha.com/examples/
APPID=$(cat ~/git/stuff/keys/wolfram_alpha) # Get one at https://products.wolframalpha.com/api/
VIEWER="kitty +kitten icat" # Use `set VIEWER display` from imagemagick if terminal does not support images
BG="transparent" # Transparent background
FG="white" # Match color to your terminal
RESPONSE=$(curl -s "https://api.wolframalpha.com/v1/result?appid=$APPID&units=metric&" --data-urlencode "i=$*" | tee /dev/tty)
# Remove next if you are fine with text only api, and don't want to see any images
test "No short answer available" = "$RESPONSE"\
&& echo ", downloading full answer..."\
&& curl -s "https://api.wolframalpha.com/v1/simple?appid=$APPID&units=metric&foreground=$FG&background=$BG" --data-urlencode "i=$*" -o /tmp/wolfram_alpha\
&& $VIEWER /tmp/wolfram_alpha\
|| exit 0