transcardbot/utils.py

23 lines
753 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()
balance = ElementTree.parse("temp.xml").findtext(".//pbtext").replace("Билет длительного пользования", "").replace(" руб.", "")
if not balance:
return
return int(balance)