This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
BWTAqua/modules/bwt.py

51 lines
1.7 KiB
Python
Raw Normal View History

2022-09-08 13:12:25 +03:00
#-*- coding: utf-8 -*-
import os
import traceback
from functions import *
from bs4 import BeautifulSoup
config = jsonLoad("config.json")
class EmptyCardException(Exception):
pass
async def getWaterLeft(cardid, filename, app=None):
url = f"https://bwtaqua.com.ua/card-topup/?id={cardid}"
try:
os.system(f'touch data/pages/{str(filename)}.html')
os.system(f'PageSaver/pageSaver "https://bwtaqua.com.ua/card-topup/?id={cardid}" > data/pages/{str(filename)}.html')
with open(f'data/pages/{str(filename)}.html') as f:
html_file = f.read()
f.close()
soup = BeautifulSoup(html_file, 'html.parser')
output = (soup.find_all("h3", class_="headline headline_center headline_pink js-payment-balance")[0].getText()).replace("Твій баланс ", "").replace(" л", "")
appendLog(f"Parsed {output} liters of water remaining (user: {str(filename)}, cardid: {cardid})")
except Exception as exp:
appendLog(f"Exception occured: {exp} (user: {str(filename)}, cardid: {cardid})")
if app != None:
await app.send_message(config["owner_id"], f"**Exception occured:**\n • User: `{str(filename)}`\n • Card: [{cardid}]({url})\n • Exception: `{exp}`\n • Traceback: `{traceback.format_exc()}`", disable_web_page_preview=True)
else:
print(f'Exception occured and could not send to user: {exp}')
output = "Failure"
return output
if __name__ == "__main__":
cardid = input("Enter card number: ")
userid = input("Enter Telegram ID (optional): ")
print(f"Card has {str(getWaterLeft(cardid, userid, app=None))} l. left")