transcardbot/utils.py

26 lines
808 B
Python
Raw Normal View History

2024-01-08 20:37:52 +03:00
from xml.etree import ElementTree
from aiohttp import ClientSession
async def tk_balance(card_number: int):
async with ClientSession() as session:
response = await session.post(
url="https://transkart.ru/api/payment/checkCard",
json={
"card": card_number
}
)
await session.close()
text = await response.text()
file = open("temp.xml", "w+")
file.write(text)
file.close()
2024-01-08 20:41:34 +03:00
try:
balance = ElementTree.parse("temp.xml").findtext(".//pbtext").replace("Билет длительного пользования", "").replace(" руб.", "")
except AttributeError:
return
2024-01-08 20:37:52 +03:00
if not balance:
return
return int(balance)