chore: Divided the functionality into folders

This commit is contained in:
Данил 2024-11-28 21:50:03 +03:00
parent f00cac9ae9
commit a89362205a
4 changed files with 59 additions and 1 deletions

22
function/get_chart.py Normal file
View file

@ -0,0 +1,22 @@
from http import HTTPStatus
import yaml
import requests
from urllib3 import HTTPSConnectionPool
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/', {
'from_currency': from_currency,
'conv_currency': conv_currency
}, timeout=3)
except requests.exceptions.ConnectionError:
return None
if not HTTPStatus(res.status_code).is_success:
return None
return res.json().get('message', None)

36
function/inline_query.py Normal file
View file

@ -0,0 +1,36 @@
import re
from aiogram import types
async def reply(result_id: str, args: list, query: types.InlineQuery) -> None:
if not args:
return
articles = []
for idx, arg in enumerate(args):
title = arg[0]
description = arg[1] if arg[1] else None
img = arg[2] if arg[2] else None
article = types.InlineQueryResultArticle(
id=f"{result_id}_{idx}",
title=re.sub(r'\[([^\[]+)\]\([^\)]+\)', '', title).replace('График', ''),
thumbnail_url=img,
description=description,
input_message_content=types.InputTextMessageContent(
message_text=title,
parse_mode='markdown'
)
)
articles.append(article)
await query.answer(
results=articles,
parse_mode='markdown',
cache_time=0,
is_personal=True
)

View file

@ -5,7 +5,7 @@ import json
import re
from decimal import Decimal, ROUND_DOWN
from function.format_number import format_number
from utils.format_number import format_number
config = yaml.safe_load(open('config.yaml'))