Improved imports
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
from subprocess import run
|
||||
from os import makedirs, path
|
||||
from subprocess import check_output
|
||||
from traceback import format_exc
|
||||
from uuid import uuid4
|
||||
from functions import *
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
@@ -16,16 +18,19 @@ async def getWaterLeft(cardid, filename, app=None):
|
||||
|
||||
try:
|
||||
|
||||
run(["touch", f"data/pages/{str(filename)}.html"])
|
||||
# if path.exists(f"data/pages/{str(filename)}.html") is False:
|
||||
# run(["touch", f"data/pages/{str(filename)}.html"])
|
||||
|
||||
if config["use_compiled_page_saver"]:
|
||||
run(["PageSaver/pageSaver", f"\"https://bwtaqua.com.ua/card-topup/?id={cardid}\"", ">", f"data/pages/{str(filename)}.html"])
|
||||
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"])
|
||||
html_file = proc.decode("utf-8")
|
||||
else:
|
||||
run(["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()
|
||||
# with open(f'data/pages/{str(filename)}.html') as f:
|
||||
# html_file = f.read()
|
||||
# f.close()
|
||||
|
||||
soup = BeautifulSoup(html_file, 'html.parser')
|
||||
|
||||
@@ -36,11 +41,20 @@ async def getWaterLeft(cardid, filename, app=None):
|
||||
except Exception as exp:
|
||||
|
||||
appendLog(f"Exception occured: {exp} (user: {str(filename)}, cardid: {cardid})")
|
||||
|
||||
try:
|
||||
tmp_name = str(uuid4())
|
||||
makedirs("tmp", exist_ok=True)
|
||||
with open(path.join("tmp", tmp_name), "w", encoding="utf-8") as f:
|
||||
f.write(html_file)
|
||||
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 • 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:
|
||||
print(f'Exception occured and could not send to user: {exp}')
|
||||
appendLog(f'Exception occured and could not send to user: {exp}')
|
||||
|
||||
output = "Failure"
|
||||
|
||||
|
Reference in New Issue
Block a user