mirror of
https://github.com/Redume/Shirino.git
synced 2025-04-02 18:57:34 +03:00
chore: Rewrote the date retrieval function if there is no data
This commit is contained in:
parent
c0680d38d5
commit
655cb35260
2 changed files with 6 additions and 9 deletions
|
@ -1,10 +1,9 @@
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
import pytz
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ class Converter:
|
||||||
|
|
||||||
self.conv_amount = format_number(Decimal(self.conv_amount))
|
self.conv_amount = format_number(Decimal(self.conv_amount))
|
||||||
|
|
||||||
async def get_timezone(self) -> str:
|
async def get_lastdate(self) -> str:
|
||||||
async with aiohttp.ClientSession(
|
async with aiohttp.ClientSession(
|
||||||
timeout=aiohttp.ClientTimeout(total=3)
|
timeout=aiohttp.ClientTimeout(total=3)
|
||||||
) as session:
|
) as session:
|
||||||
|
@ -37,11 +36,11 @@ class Converter:
|
||||||
return 'UTC'
|
return 'UTC'
|
||||||
|
|
||||||
data = await res.json()
|
data = await res.json()
|
||||||
return data.get('timezone', 'UTC')
|
|
||||||
|
return data.get('last_date', datetime.now() - timedelta(1))
|
||||||
|
|
||||||
async def kekkai(self) -> bool:
|
async def kekkai(self) -> bool:
|
||||||
timezone = pytz.timezone(await self.get_timezone())
|
date = datetime.strftime(await self.get_lastdate(), '%Y-%m-%d')
|
||||||
date = datetime.now(timezone).strftime('%Y-%m-%d')
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=3)) as session:
|
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=3)) as session:
|
||||||
async with session.get(f'{config['kekkai_instance']}/api/getRate/', params={
|
async with session.get(f'{config['kekkai_instance']}/api/getRate/', params={
|
||||||
|
@ -58,7 +57,6 @@ class Converter:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def ddg(self) -> None:
|
async def ddg(self) -> None:
|
||||||
async with aiohttp.ClientSession(
|
async with aiohttp.ClientSession(
|
||||||
timeout=aiohttp.ClientTimeout(total=3)
|
timeout=aiohttp.ClientTimeout(total=3)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
aiohttp~=3.9.5
|
aiohttp~=3.9.5
|
||||||
PyYAML~=6.0.1
|
PyYAML~=6.0.1
|
||||||
aiogram~=3.15.0
|
aiogram~=3.15.0
|
||||||
pytz~=2025.2
|
|
Loading…
Add table
Add a link
Reference in a new issue