#!/usr/bin/env python3

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

import json
import saxo

@saxo.pipe
def btc(arg):
    if arg and (arg not in {"£", ":gbp"}):
        return "This command takes no argument"
    url = "https://api.bitcoinaverage.com/ticker/global/all"
    page = saxo.request(url)
    data = json.loads(page["text"])
    if arg in {"£", ":gbp"}:
        return str(data["GBP"]["last"]) + " GBP (BitcoinAverage)"
    return str(data["USD"]["last"]) + " USD (BitcoinAverage)"
