From 53c84dd613983f16d0e5e8abc58a641df5c3b2b3 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 3 May 2024 22:47:45 +0200 Subject: [PATCH] handling oldFiles --- .../groups/shx-order-package-label/script.py | 2 ++ .../shx-order-voucher-code-activated/script.py | 7 +++++++ .../groups/shx-order-voucher-codes/script.py | 7 +++---- groupTasks/groups/shx-product-label/script.py | 3 ++- .../utils/__pycache__/utils.cpython-39.pyc | Bin 997 -> 1281 bytes groupTasks/libs/utils/utils.py | 13 ++++++++++++- 6 files changed, 26 insertions(+), 6 deletions(-) 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 f5a540b5a9bb96672bcf2bf7ccd7207633b89384..5ba044b17ac1f3dfd126d3d60eed458c7e4cb2ab 100644 GIT binary patch delta 460 zcmX|7%}T>S5Z>ARwzknzTS}375hHl?)`O@Nyr`%k1SG_6(xy$Dx*NrVr3k)&#n?h%q`M%ki-TC>mUdv8Ut(FPO$Jt@@YrH$H;|_X^Fi42ELhzvQsYeUc zJdIJNy%A4mIx`RrW-<%WWN=Mf`}3v-V1A9D3;VKk$)c+;U?DH)Esry#1`j6vkn31W z8q=U33Yq^<0W!bP4#3H0+RnU=!5->b0GWk)f+~*CWMl{n%3uk+laYm{*eSVd&Pb*& zj3SCHy^tkU3gn@NS(eHI91UBg=boJ=tQ#kxaBWFbA@ymH4Wt=9&ts7ZX(b3O=F${{ z$1F~yK2D!PsSne5f>Vq!|?dn-5%x$^^VXA qIM4vzM($eNK;WB%)Cq4W+EQji8MP4J&cC(YtqM{bibHMNZvF$`@@;Ma delta 193 zcmZqVddkk1$ji&c00e$+rfEhj6ZvGcRDiq`h7`sehA0Tl7{!>vl)~J?5XF?jlEMn4 znNt{p88q28=7=#evTSZTZl VX-=vgBT%fE4M=b>axigl002HhDJ1{^ 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