From d8d6635987fc6d68ec5a8346e2b27998cf2f0497 Mon Sep 17 00:00:00 2001 From: Redume Date: Thu, 9 Jan 2025 00:04:31 +0300 Subject: [PATCH] refactor: Rewrote the creation of graphs on aiohttp --- functions/create_chart.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 functions/create_chart.py diff --git a/functions/create_chart.py b/functions/create_chart.py new file mode 100644 index 0000000..078effb --- /dev/null +++ b/functions/create_chart.py @@ -0,0 +1,19 @@ +import yaml +import aiohttp + +from http import HTTPStatus + +config = yaml.safe_load(open('config.yaml')) + +async def create_chart(from_currency: str, conv_currency: str) -> (dict, None): + async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=3)) as session: + async with session.get(f'{config["kekkai_instance"]}/api/getChart/week/', params={ + 'from_currency': from_currency, + 'conv_currency': conv_currency + }) as res: + if not HTTPStatus(res.status).is_success: + return None + + data = await res.json() + + return data.get('message', None)