mirror of
https://github.com/Redume/Shirino.git
synced 2025-02-04 17:58:58 +03:00
27 lines
845 B
Python
27 lines
845 B
Python
import yaml
|
|
import requests
|
|
from http import HTTPStatus
|
|
|
|
config = yaml.safe_load(open('config.yaml'))
|
|
|
|
def get_chart(from_currency: str, conv_currency: str) -> (dict, None):
|
|
try:
|
|
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
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"There was an error: {e}")
|
|
return None
|