Skip to content

Commit 58dc519

Browse files
committed
Switch to letting requests handle url parameters
1 parent 3af1de3 commit 58dc519

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

plugins/cryptocurrency.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
from 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)

0 commit comments

Comments
 (0)