2024-11-28 21:50:03 +03:00
|
|
|
import yaml
|
|
|
|
import requests
|
2025-01-07 13:58:08 +03:00
|
|
|
from http import HTTPStatus
|
2024-11-28 21:50:03 +03:00
|
|
|
|
|
|
|
config = yaml.safe_load(open('config.yaml'))
|
|
|
|
|
|
|
|
def get_chart(from_currency: str, conv_currency: str) -> (dict, None):
|
|
|
|
try:
|
2025-01-07 13:58:08 +03:00
|
|
|
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
|
2024-11-28 21:50:03 +03:00
|
|
|
except requests.exceptions.ConnectionError:
|
2025-01-07 13:58:08 +03:00
|
|
|
print("API connection error.")
|
2024-11-28 21:50:03 +03:00
|
|
|
return None
|
2025-01-07 13:58:08 +03:00
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
print(f"There was an error: {e}")
|
2024-11-28 21:50:03 +03:00
|
|
|
return None
|