Add get_usd_rate
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import random
|
||||
import re
|
||||
import json
|
||||
|
||||
import aiohttp
|
||||
import asyncpg
|
||||
|
||||
from bot import bot
|
||||
@@ -9,6 +11,21 @@ from database import get_servers_from_db
|
||||
from logger import logger
|
||||
|
||||
|
||||
async def get_usd_rate():
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get('https://www.cbr-xml-daily.ru/daily_json.js') as response:
|
||||
if response.status == 200:
|
||||
data = await response.text()
|
||||
usd = float(json.loads(data)['Valute']['USD']['Value'])
|
||||
else:
|
||||
usd = 100 # Default value if request fails
|
||||
except Exception as e:
|
||||
logger.exception(f"Error fetching USD rate: {e}")
|
||||
usd = 100 # Default value if an exception occurs
|
||||
return usd
|
||||
|
||||
|
||||
def sanitize_key_name(key_name: str) -> str:
|
||||
"""
|
||||
Очищает название ключа, оставляя только допустимые символы.
|
||||
|
||||
Reference in New Issue
Block a user