File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616
1717from cloudbot import hook
1818
19- API_URL = "https://api.coinmarketcap.com/v1/ticker/{}?convert={}"
19+ API_URL = "https://api.coinmarketcap.com/v1/ticker/{}"
20+
21+
22+ def get_request (ticker , currency ):
23+ return requests .get (API_URL .format (quote_plus (ticker )), params = {'convert' : currency })
2024
2125
2226# aliases
@@ -48,15 +52,13 @@ def crypto_command(text):
4852 args = text .split ()
4953 ticker = args .pop (0 )
5054
55+ if not args :
56+ currency = 'USD'
57+ else :
58+ currency = args .pop (0 ).upper ()
59+
5160 try :
52- if not args :
53- currency = 'USD'
54- else :
55- currency = args .pop (0 ).upper ()
56-
57- encoded_ticker = quote_plus (ticker )
58- encoded_currency = quote_plus (currency )
59- request = requests .get (API_URL .format (encoded_ticker , encoded_currency ))
61+ request = get_request (ticker , currency )
6062 request .raise_for_status ()
6163 except (requests .exceptions .HTTPError , requests .exceptions .ConnectionError ) as e :
6264 return "Could not get value: {}" .format (e )
You can’t perform that action at this time.
0 commit comments