mirror of
https://github.com/Redume/Shirino.git
synced 2025-07-03 18:50:55 +01:00
chore: Transmitted the receipt of the graph
This commit is contained in:
parent
159036957a
commit
81a57e4b9e
1 changed files with 18 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
|||
from http import HTTPStatus
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import yaml
|
||||
import aiohttp
|
||||
|
@ -8,19 +9,22 @@ config = yaml.safe_load(open('../config.yaml', 'r', encoding='utf-8'))
|
|||
async def create_chart(
|
||||
from_currency: str,
|
||||
conv_currency: str,
|
||||
period: str) -> (dict, None):
|
||||
async with aiohttp.ClientSession(
|
||||
timeout=aiohttp.ClientTimeout(total=3)
|
||||
) as session:
|
||||
async with session.get(
|
||||
f'{config["kekkai_instance"]}/api/getChart/{period}/',
|
||||
params={
|
||||
'from_currency': from_currency,
|
||||
'conv_currency': conv_currency
|
||||
}) as res:
|
||||
period: str,
|
||||
backend: str) -> (str, None):
|
||||
params = {
|
||||
'from_currency': from_currency,
|
||||
'conv_currency': conv_currency,
|
||||
'period': period,
|
||||
'backend': backend
|
||||
}
|
||||
|
||||
base_url = f'{config["kekkai_instance"]}/api/getChart/'
|
||||
query_string = urlencode(params)
|
||||
full_url = f'{base_url}?{query_string}'
|
||||
|
||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=3)) as session:
|
||||
async with session.get(full_url) as res:
|
||||
if not HTTPStatus(res.status).is_success:
|
||||
return None
|
||||
|
||||
data = await res.json()
|
||||
|
||||
return data.get('detail', None)
|
||||
return full_url
|
||||
|
|
Loading…
Add table
Reference in a new issue