@@ -66,13 +66,15 @@ def crypto_command(text):
6666 if "error" in data :
6767 return "{}." .format (data ['error' ])
6868
69- updated_time = datetime .fromtimestamp (float (data [0 ]['last_updated' ]))
69+ data = data [0 ]
70+
71+ updated_time = datetime .fromtimestamp (float (data ['last_updated' ]))
7072 if (datetime .today () - updated_time ).days > 2 :
7173 # the API retains data for old ticker names that are no longer updated
7274 # in these cases we just return a "not found" message
7375 return "Currency not found."
7476
75- change = float (data [0 ][ 'percent_change_24h' ])
77+ change = float (data ['percent_change_24h' ])
7678 if change > 0 :
7779 change_str = "\x03 3 {}%\x0f " .format (change )
7880 elif change < 0 :
@@ -89,9 +91,14 @@ def crypto_command(text):
8991 else :
9092 currency_sign = ''
9193
92- return "{} // \x03 07{}{:,.2f}\x0f {} - {:,.7f} BTC // {} change" .format (data [0 ]['symbol' ],
94+ try :
95+ converted_value = data ['price_' + currency .lower ()]
96+ except LookupError :
97+ return "Unable to convert to currency '{}'" .format (currency )
98+
99+ return "{} // \x03 07{}{:,.2f}\x0f {} - {:,.7f} BTC // {} change" .format (data ['symbol' ],
93100 currency_sign ,
94- float (data [ 0 ][ 'price_' + currency . lower ()] ),
101+ float (converted_value ),
95102 currency .upper (),
96- float (data [0 ][ 'price_btc' ]),
103+ float (data ['price_btc' ]),
97104 change_str )
0 commit comments