Formatted everything with black

This commit is contained in:
2023-03-18 00:52:15 +01:00
parent dcf82ab6f2
commit c3dd6f61d6
4 changed files with 231 additions and 131 deletions

View File

@@ -1,4 +1,4 @@
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from os import makedirs, path
from subprocess import check_output
@@ -9,39 +9,60 @@ 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:
async def getWaterLeft(cardid, filename, app=None):
url = f"https://bwtaqua.com.ua/card-topup/?id={cardid}"
try:
# if path.exists(f"data/pages/{str(filename)}.html") is False:
# run(["touch", f"data/pages/{str(filename)}.html"])
appendLog(f"Trying to get liters for url '{url}'")
if config["use_compiled_page_saver"] is True:
proc = check_output(["PageSaver/pageSaver", f"https://bwtaqua.com.ua/card-topup/?id={cardid}"]) #, ">", f"data/pages/{str(filename)}.html"])
proc = check_output(
[
"PageSaver/pageSaver",
f"https://bwtaqua.com.ua/card-topup/?id={cardid}",
]
) # , ">", f"data/pages/{str(filename)}.html"])
html_file = proc.decode("utf-8")
else:
proc = check_output(["node", "./PageSaver/pageSaver.js", f"https://bwtaqua.com.ua/card-topup/?id={cardid}"]) #, ">", f"data/pages/{str(filename)}.html"])
proc = check_output(
[
"node",
"./PageSaver/pageSaver.js",
f"https://bwtaqua.com.ua/card-topup/?id={cardid}",
]
) # , ">", f"data/pages/{str(filename)}.html"])
html_file = proc.decode("utf-8")
# 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})")
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})")
try:
@@ -52,19 +73,23 @@ async def getWaterLeft(cardid, filename, app=None):
except NameError:
tmp_name = "N/A"
appendLog(f"'html_file' is not defined so I won't gather any tmp data")
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 • TMP UUID: `{tmp_name}`\n • Traceback: `{format_exc()}`", disable_web_page_preview=True)
await app.send_message(
config["owner_id"],
f"**Exception occured:**\n • User: `{str(filename)}`\n • Card: [{cardid}]({url})\n • Exception: `{exp}`\n • TMP UUID: `{tmp_name}`\n • Traceback: `{format_exc()}`",
disable_web_page_preview=True,
)
else:
appendLog(f'Exception occured and could not send to user: {exp}')
appendLog(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")

View File

@@ -1,22 +1,22 @@
RESET = '\u001b[0m'
RESET = "\u001b[0m"
BLACK = '\u001b[30m'
RED = '\u001b[31m'
GREEN = '\u001b[32m'
YELLOW = '\u001b[33m'
BLUE = '\u001b[34m'
MAGENTA = '\u001b[35m'
CYAN = '\u001b[36m'
WHITE = '\u001b[37m'
BLACK = "\u001b[30m"
RED = "\u001b[31m"
GREEN = "\u001b[32m"
YELLOW = "\u001b[33m"
BLUE = "\u001b[34m"
MAGENTA = "\u001b[35m"
CYAN = "\u001b[36m"
WHITE = "\u001b[37m"
BBLACK = '\u001b[30;1m'
BRED = '\u001b[31;1m'
BGREEN = '\u001b[32;1m'
BYELLOW = '\u001b[33;1m'
BBLUE = '\u001b[34;1m'
BMAGENTA = '\u001b[35;1m'
BCYAN = '\u001b[36;1m'
BWHITE = '\u001b[37;1m'
BBLACK = "\u001b[30;1m"
BRED = "\u001b[31;1m"
BGREEN = "\u001b[32;1m"
BYELLOW = "\u001b[33;1m"
BBLUE = "\u001b[34;1m"
BMAGENTA = "\u001b[35;1m"
BCYAN = "\u001b[36;1m"
BWHITE = "\u001b[37;1m"
ULINE = '\u001b[4m'
REVERSE = '\u001b[7m'
ULINE = "\u001b[4m"
REVERSE = "\u001b[7m"