mirror of
https://github.com/Redume/Shirino.git
synced 2025-02-04 09:58:57 +03:00
chore: add print in execpt
This commit is contained in:
parent
b7396d4634
commit
f103970be2
1 changed files with 17 additions and 12 deletions
|
@ -1,22 +1,27 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
import yaml
|
||||
import requests
|
||||
from urllib3 import HTTPSConnectionPool
|
||||
from http import HTTPStatus
|
||||
|
||||
config = yaml.safe_load(open('config.yaml'))
|
||||
|
||||
def get_chart(from_currency: str, conv_currency: str) -> (dict, None):
|
||||
try:
|
||||
res = requests.get(f'{config['kekkai_instance']}/api/getChart/week/', {
|
||||
response = requests.get(f'{config["kekkai_instance"]}/api/getChart/week/', params={
|
||||
'from_currency': from_currency,
|
||||
'conv_currency': conv_currency
|
||||
}, timeout=3)
|
||||
|
||||
if not HTTPStatus(response.status_code).is_success:
|
||||
return None
|
||||
|
||||
try:
|
||||
data = response.json()
|
||||
return data.get('message', None)
|
||||
except ValueError:
|
||||
return None
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("API connection error.")
|
||||
return None
|
||||
|
||||
if not HTTPStatus(res.status_code).is_success:
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"There was an error: {e}")
|
||||
return None
|
||||
|
||||
|
||||
return res.json().get('message', None)
|
Loading…
Add table
Reference in a new issue