# -*- encoding: utf-8 -*-
from __future__ import unicode_literals, print_function, division


def command_btc(bot, user, channel, args):
    """Display current BTC exchange rates from mtgox. Usage: btc [whitespace separated list of currency codes]"""
    currencies = ["EUR"]

    if args:
        currencies = args.split(" ")

    rates = []

    for currency in currencies:
        rate = gen_string(bot, currency)
        if rate:
            rates.append(rate)

    if rates:
        return bot.say(channel, "1 BTC = %s" % " | ".join(rates))


def gen_string(bot, currency):
    r = bot.get_url("http://data.mtgox.com/api/1/BTC%s/ticker" % currency)

    if r.json()['result'] != 'success':
        return None

    data = r.json()['return']

    avg  = data['avg']['display_short']
    low  = data['low']['display_short']
    high = data['high']['display_short']
    vol = data['vol']['display_short']

    return "%s avg:%s low:%s high:%s vol:%s" % (currency.upper(), avg, low, high, vol)

@@ -321,16 +321,434 @@
 t(%22 %22)%0A%0A
+    return bot.say(channel, get_coin_value(bot, %22BTC%22, currencies))%0A%0A%0Adef command_ltc(bot, user, channel, args):%0A    %22%22%22Display current LTC exchange rates from mtgox. Usage: ltc %5Bwhitespace separated list of currency codes%5D%22%22%22%0A    currencies = %5B%22EUR%22%5D%0A%0A    if args:%0A        currencies = args.split(%22 %22)%0A%0A    return bot.say(channel, get_coin_value(bot, %22LTC%22, currencies))%0A%0A%0Adef get_coin_value(bot, coin, currencies):%0A%0A
     rate
@@ -809,32 +809,38 @@
  gen_string(bot,
+ coin,
  currency)%0A     
@@ -916,39 +916,21 @@
 urn 
-bot.say(channel, %221 BTC
+%221 %25s
  = %25s%22 %25
  %22 %7C
@@ -925,16 +925,23 @@
  = %25s%22 %25
+ (coin,
  %22 %7C %22.j
@@ -948,26 +948,56 @@
 oin(rates))%0A
+    else:%0A        return None
 %0A%0A
+%0A
 def gen_stri
@@ -1003,16 +1003,28 @@
 ing(bot,
+ coin=%22BTC%22,
  currenc
@@ -1024,16 +1024,22 @@
 currency
+=%22EUR%22
 ):%0A    r
@@ -1082,19 +1082,18 @@
 m/api/1/
-BTC
+%25s
 %25s/ticke
@@ -1096,16 +1096,23 @@
 icker%22 %25
+ (coin,
  currenc
@@ -1113,16 +1113,17 @@
 urrency)
+)
 %0A%0A    if

Add support for LTC in mtgox