#!/usr/bin/env python3

# http://inamidst.com/saxo/
# Created by Sean B. Palmer

import os
import subprocess

import saxo

def utf8(obj):
    return str(obj).encode("utf-8", "replace")

# TODO: Generic shell command
def shell(*args):
    args = [utf8(arg) for arg in args]
    output = subprocess.check_output(args)
    return str(output, "utf-8").rstrip("\r\n")

@saxo.pipe
def wa(arg):
    if not arg:
        return "Compute an expression using Wolfram|Alpha"
    c = os.path.join(os.path.dirname(__file__), "c")
    return shell(c, ":long " + arg)
