mirror of
https://github.com/Redume/Shirino.git
synced 2024-12-25 17:53:46 +03:00
fix: Added an exception and fixed the returned result on error
This commit is contained in:
parent
d7126e657e
commit
4fd2d3d182
1 changed files with 14 additions and 10 deletions
|
@ -54,22 +54,26 @@ class Converter:
|
|||
|
||||
self.conv_amount = float(conv_amount)
|
||||
|
||||
|
||||
def kekkai(self) -> bool:
|
||||
date = datetime.today().strftime('%Y-%m-%d')
|
||||
|
||||
res = requests.get(f'{config['kekkai_instance']}/api/getRate/', {
|
||||
'from_currency': self.from_currency,
|
||||
'conv_currency': self.conv_currency,
|
||||
'date': date
|
||||
}, timeout=3)
|
||||
try:
|
||||
res = requests.get(f'{config['kekkai_instance']}/api/getRate/', {
|
||||
'from_currency': self.from_currency,
|
||||
'conv_currency': self.conv_currency,
|
||||
'date': date
|
||||
}, timeout=3)
|
||||
|
||||
data = res.json()
|
||||
data = res.json()
|
||||
|
||||
if not HTTPStatus(res.status_code).is_success:
|
||||
return None
|
||||
if not HTTPStatus(res.status_code).is_success:
|
||||
return False
|
||||
|
||||
self.conv_amount = float(data.get('rate') * self.amount)
|
||||
self.conv_amount = float(data.get('rate') * self.amount)
|
||||
|
||||
return True
|
||||
return True
|
||||
except requests.exceptions.ConnectionError:
|
||||
return False
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue