diff --git a/groupTasks/groups/shx-order-package-label/script.py b/groupTasks/groups/shx-order-package-label/script.py index e649395..4b2e416 100644 --- a/groupTasks/groups/shx-order-package-label/script.py +++ b/groupTasks/groups/shx-order-package-label/script.py @@ -83,6 +83,8 @@ def replacePlaceholder(): if __name__ == "__main__": + utils.move_files_back_from_old_files() + print(f"Creating package label for {customer_first_name}") downloadFile(shipping_label_url, "label.png") diff --git a/groupTasks/groups/shx-order-voucher-code-activated/script.py b/groupTasks/groups/shx-order-voucher-code-activated/script.py index 3946487..63587e3 100644 --- a/groupTasks/groups/shx-order-voucher-code-activated/script.py +++ b/groupTasks/groups/shx-order-voucher-code-activated/script.py @@ -4,6 +4,13 @@ import yaml import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText +import os + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +from libs.utils import utils + +utils.move_files_back_from_old_files() STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/" diff --git a/groupTasks/groups/shx-order-voucher-codes/script.py b/groupTasks/groups/shx-order-voucher-codes/script.py index da2b8b6..00af840 100644 --- a/groupTasks/groups/shx-order-voucher-codes/script.py +++ b/groupTasks/groups/shx-order-voucher-codes/script.py @@ -3,7 +3,6 @@ import sys import json import qrcode import subprocess -import PyPDF2 import sys import os @@ -115,7 +114,6 @@ def CreateCrmActivityLink(customerId): print(f"CreateCrmActivityLink req error {response.status_code}") sys.exit(1) - req("10 % Gutschein", "https://shinnex.de") req("5 € Gutschein", productUrl) req("10 € Gutschein", f"https://docs.google.com/forms/d/e/1FAIpQLSd2GXFbidzazuQnh_Lf2mgeA1npuwHkWjsdmjrxDmSkDQTfew/viewform?entry.347359844={orderId}") @@ -141,7 +139,7 @@ def create_qrcode(type, id): img.save(f"./{type}.png") # Display the generated QR code image - img.show() + #img.show() def GetCustomerActivityLinks(customerId): @@ -220,7 +218,6 @@ def createPdf(sourceHtml, outputPdf): "--headless", "--no-sandbox", "--disable-gpu", - "--debug=1", "--print-to-pdf=" + outputPdf, "--run-all-compositor-stages-before-draw", "--virtual-time-budget=10000", @@ -237,6 +234,8 @@ def createPdf(sourceHtml, outputPdf): if __name__ == "__main__": + utils.move_files_back_from_old_files() + CheckIfCrmCustomerExists() ReplaceHtmlVariables() diff --git a/groupTasks/groups/shx-product-label/script.py b/groupTasks/groups/shx-product-label/script.py index 0d58149..456dd05 100644 --- a/groupTasks/groups/shx-product-label/script.py +++ b/groupTasks/groups/shx-product-label/script.py @@ -41,7 +41,6 @@ def createPdf(sourceHtml, outputPdf): "--headless", "--no-sandbox", "--disable-gpu", - "--debug=1", "--print-to-pdf=" + outputPdf, "--run-all-compositor-stages-before-draw", "--virtual-time-budget=10000", @@ -57,6 +56,8 @@ def createPdf(sourceHtml, outputPdf): sys.exit(1) if __name__ == "__main__": + utils.move_files_back_from_old_files() + # replace placeholders in index.js p_type_id = product_type_id.split(" ")[0].split("#")[1] diff --git a/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc b/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc index f5a540b..5ba044b 100644 Binary files a/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc and b/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc differ diff --git a/groupTasks/libs/utils/utils.py b/groupTasks/libs/utils/utils.py index 255edeb..319dfb2 100644 --- a/groupTasks/libs/utils/utils.py +++ b/groupTasks/libs/utils/utils.py @@ -1,5 +1,7 @@ import subprocess import PyPDF2 +import os +import shutil def clear_workspace(files): if not files or not isinstance(files, list) or len(files) == 0: @@ -31,4 +33,13 @@ def merge_pdfs(pdf1_path, pdf2_path, output_path): # save the combined PDF with open(output_path, 'wb') as output_file: - pdf_writer.write(output_file) \ No newline at end of file + pdf_writer.write(output_file) + + +# If a script failes the files are moved to the old_files directory so we need to move them back so that the paths defined in the files are correct +def move_files_back_from_old_files(): + # check if old_files directory exists and move files back + if os.path.exists("oldFiles"): + for file in os.listdir("oldFiles"): + shutil.move(os.path.join("oldFiles", file), file) + os.rmdir("oldFiles") \ No newline at end of file