-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.py
More file actions
33 lines (25 loc) · 1.18 KB
/
extension.py
File metadata and controls
33 lines (25 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import requests
from config import keys
class ConvertationException(Exception):
pass
class Converter:
@staticmethod
def get_price(base, quote, amount):
if base == quote:
raise ConvertationException(f'Зачем переводить {keys[base]} в {keys[base]} 🤦🏻')
try:
allert = int(amount)
except ValueError:
raise ConvertationException('Количество вводиться с помощью ЦИФР, кэп!')
try:
base_ticker = keys[base]
except KeyError:
raise ConvertationException(f'Нет валюты {base} в этом списке /value\nты инструкции вообще читаешь?')
try:
quote_ticker = keys[quote]
except KeyError:
raise ConvertationException(f'Загляни сюда-ка сюда /value,\nвидишь валюту {quote} в списке доступных?')
r = requests.get(f'https://min-api.cryptocompare.com/data/price?fsym={keys[base]}&tsyms={keys[quote]}')
total = float(json.loads(r.content)[keys[quote]])
return total