mirror of
https://github.com/Redume/Shirino.git
synced 2025-02-04 09:58:57 +03:00
chore: Removed all functionality
This commit is contained in:
parent
f3ca3b8f76
commit
380b4cba1f
4 changed files with 0 additions and 155 deletions
|
@ -1,27 +0,0 @@
|
||||||
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
|
|
|
@ -1,36 +0,0 @@
|
||||||
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
|
|
||||||
)
|
|
|
@ -1,78 +0,0 @@
|
||||||
import yaml
|
|
||||||
import requests
|
|
||||||
|
|
||||||
import json
|
|
||||||
import re
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from http import HTTPStatus
|
|
||||||
|
|
||||||
from decimal import Decimal, ROUND_DOWN
|
|
||||||
from utils.format_number import format_number
|
|
||||||
|
|
||||||
config = yaml.safe_load(open('config.yaml'))
|
|
||||||
|
|
||||||
|
|
||||||
class Converter:
|
|
||||||
def __init__(self):
|
|
||||||
self.amount: float = 1.0
|
|
||||||
self.conv_amount: float = 0.0
|
|
||||||
self.from_currency: str = ''
|
|
||||||
self.conv_currency: str = ''
|
|
||||||
|
|
||||||
|
|
||||||
def convert(self) -> None:
|
|
||||||
if not self.kekkai() and not self.ddg():
|
|
||||||
raise RuntimeError('Failed to convert via Kekkai or DDG')
|
|
||||||
|
|
||||||
number = Decimal(str(self.conv_amount))
|
|
||||||
self.conv_amount = format_number(number.quantize(Decimal('1.00'), rounding=ROUND_DOWN))
|
|
||||||
|
|
||||||
|
|
||||||
def ddg(self) -> bool:
|
|
||||||
try:
|
|
||||||
res = requests.get(
|
|
||||||
f'https://duckduckgo.com/js/spice/currency/'
|
|
||||||
f'{self.amount}/{self.from_currency}/{self.conv_currency}',
|
|
||||||
timeout=3
|
|
||||||
)
|
|
||||||
|
|
||||||
data = json.loads(re.findall(r'\(\s*(.*)\s*\);$', res.text)[0])
|
|
||||||
|
|
||||||
for key in ['terms', 'privacy', 'timestamp']:
|
|
||||||
data.pop(key, None)
|
|
||||||
|
|
||||||
if not data.get('to'):
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.conv_amount = float(data['to'][0].get('mid', 0.0))
|
|
||||||
return True
|
|
||||||
|
|
||||||
except (requests.exceptions.RequestException, json.JSONDecodeError, IndexError) as e:
|
|
||||||
print(f"Error when requesting DDG: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def kekkai(self) -> bool:
|
|
||||||
date = datetime.today().strftime('%Y-%m-%d')
|
|
||||||
try:
|
|
||||||
res = requests.get(
|
|
||||||
f"{config['kekkai_instance']}/api/getRate/",
|
|
||||||
params={
|
|
||||||
'from_currency': self.from_currency,
|
|
||||||
'conv_currency': self.conv_currency,
|
|
||||||
'date': date,
|
|
||||||
'conv_amount': self.amount
|
|
||||||
},
|
|
||||||
timeout=3
|
|
||||||
)
|
|
||||||
|
|
||||||
if res.status_code != HTTPStatus.OK:
|
|
||||||
return False
|
|
||||||
|
|
||||||
data = res.json()
|
|
||||||
self.conv_amount = data.get('conv_amount', 0.0)
|
|
||||||
return True
|
|
||||||
|
|
||||||
except (requests.exceptions.ConnectionError, json.JSONDecodeError) as e:
|
|
||||||
print(f"Error when querying Kekkai: {e}")
|
|
||||||
return False
|
|
|
@ -1,14 +0,0 @@
|
||||||
def format_number(number):
|
|
||||||
number_str = str(number)
|
|
||||||
|
|
||||||
if '.' in number_str:
|
|
||||||
integer_part, fractional_part = number_str.split('.')
|
|
||||||
else:
|
|
||||||
integer_part, fractional_part = number_str, ''
|
|
||||||
|
|
||||||
formatted_integer_part = '{:,}'.format(int(integer_part)).replace(',', ' ')
|
|
||||||
|
|
||||||
if fractional_part:
|
|
||||||
return formatted_integer_part + '.' + fractional_part
|
|
||||||
else:
|
|
||||||
return formatted_integer_part
|
|
Loading…
Add table
Reference in a new issue