From 1d6ad5e927de134af46cc4364f12dc7fa4d44ecc Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 14 May 2024 22:23:56 +0200 Subject: [PATCH] all in one task for order --- .../groups/shx-all-in-one-order/empty.py | 0 .../groups/shx-all-in-one-order/index.json | 99 ++++++++++++++++++ .../order-package-label-script.py | 11 ++ .../order-voucher-codes-script.py | 11 ++ .../product-label-script.py | 9 ++ .../utils/__pycache__/utils.cpython-39.pyc | Bin 1281 -> 3053 bytes groupTasks/libs/utils/utils.py | 74 ++++++++++++- 7 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 groupTasks/groups/shx-all-in-one-order/empty.py create mode 100644 groupTasks/groups/shx-all-in-one-order/index.json create mode 100644 groupTasks/groups/shx-all-in-one-order/order-package-label-script.py create mode 100644 groupTasks/groups/shx-all-in-one-order/order-voucher-codes-script.py create mode 100644 groupTasks/groups/shx-all-in-one-order/product-label-script.py diff --git a/groupTasks/groups/shx-all-in-one-order/empty.py b/groupTasks/groups/shx-all-in-one-order/empty.py new file mode 100644 index 0000000..e69de29 diff --git a/groupTasks/groups/shx-all-in-one-order/index.json b/groupTasks/groups/shx-all-in-one-order/index.json new file mode 100644 index 0000000..b28e916 --- /dev/null +++ b/groupTasks/groups/shx-all-in-one-order/index.json @@ -0,0 +1,99 @@ +{ + "category": "Shinnex", + "name": "All-in-One Bestelltask", + "globalInputs": [], + "tasks": [ + { + "name": "Gummibärchen einpacken", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Produktschilder ausdrucken", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "product-label-script.py", + "parameters": [ + { + "parameterName": "label_paper_position", + "type": "text", + "displayName": "Position auf dem A4 Blatt (Beginnend mit 1 von oben links) (Mit Komma trennbar wie z. B. 1,3,7)" + }, + { + "parameterName": "product_type_id", + "type": "select", + "displayName": "Produkttyp auswählen", + "options": [ + "#32420; Gizmo die Eidechse; Grün, Blau, Orange; (Glänzend)", + "#92784; Gizmo die Eidechse; Glitzer Grün; (Seidenmatt)", + "#36521; Charlie das Häschen; Hellbraun; (Matt)", + "#48273; Charlie das Häschen; Gold; (Glänzend)", + "#71936; Ruby die Schlange; Feuerrot; (Glänzend)", + "#58324; Ruby die Schlange; Rot/Blau; (Glänzend)", + "#21433; Bruno der Dino; Grün/Blau/Orange; (Glänzend)", + "#57953; Bruno der Dino; Rot/Blau; (Glänzend)", + "#90578; Bruno der Dino; Gold; (Glänzend)", + "#51563; Bruno der Dino; Himmelblau; (Fluoreszierend)" + ] + } + ] + }, + { + "name": "Gutscheincodes für Bestellung erstellen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "order-voucher-codes-script.py", + "parameters": [ + { + "parameterName": "orderId", + "type": "text", + "displayName": "Bestellnummer" + }, + { + "parameterName": "customerEmail", + "type": "text", + "displayName": "E-Mail vom Kunden" + }, + { + "parameterName": "customerName", + "type": "text", + "displayName": "Vorname vom Kunden" + }, + { + "parameterName": "productUrl", + "type": "text", + "displayName": "URL vom Produkt (Shopify) (z. B. https://shinnex.de/products/gizmo) (für Direktweiterleitung 5 € Gutschein QR-Code)" + }, + { + "parameterName": "discountCode", + "type": "text", + "displayName": "10 % Gutscheincode für den Kunden (in Shopify erstellen)" + } + ] + }, + { + "name": "Versandlabel erstellen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "order-package-label-script.py", + "parameters": [ + { + "parameterName": "shipping_label_url", + "type": "text", + "displayName": "Bild-URL des Versandlabels" + }, + { + "parameterName": "customer_first_name", + "type": "text", + "displayName": "Vorname des Kunden" + } + ] + } + ] +} \ No newline at end of file diff --git a/groupTasks/groups/shx-all-in-one-order/order-package-label-script.py b/groupTasks/groups/shx-all-in-one-order/order-package-label-script.py new file mode 100644 index 0000000..885a297 --- /dev/null +++ b/groupTasks/groups/shx-all-in-one-order/order-package-label-script.py @@ -0,0 +1,11 @@ +import sys +import os + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +from libs.utils import utils + +if __name__ == "__main__": + utils.delete_folder("oldFiles") + + utils.execute_another_group_task("../../groups/shx-order-package-label/", "script.py") diff --git a/groupTasks/groups/shx-all-in-one-order/order-voucher-codes-script.py b/groupTasks/groups/shx-all-in-one-order/order-voucher-codes-script.py new file mode 100644 index 0000000..5b0043a --- /dev/null +++ b/groupTasks/groups/shx-all-in-one-order/order-voucher-codes-script.py @@ -0,0 +1,11 @@ +import sys +import os + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +from libs.utils import utils + +if __name__ == "__main__": + utils.delete_folder("oldFiles") + + utils.execute_another_group_task("../../groups/shx-order-voucher-codes/", "script.py") diff --git a/groupTasks/groups/shx-all-in-one-order/product-label-script.py b/groupTasks/groups/shx-all-in-one-order/product-label-script.py new file mode 100644 index 0000000..c460d04 --- /dev/null +++ b/groupTasks/groups/shx-all-in-one-order/product-label-script.py @@ -0,0 +1,9 @@ +import sys +import os + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +from libs.utils import utils + +if __name__ == "__main__": + utils.execute_another_group_task("../../groups/shx-product-label/", "script.py") diff --git a/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc b/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc index 5ba044b17ac1f3dfd126d3d60eed458c7e4cb2ab..293fc64f99b1f8b11d8c06a190ddbcfb4c123e92 100644 GIT binary patch literal 3053 zcma)8&2J<}6|buPn4TWnYaA)N8IaX10W#69y=yKItENtn-jxF8Tl|nkdVX-G& z>7n$cFIy;EGLUVQfed8_Wm~SuRg|GzlQ&RyB>#x@)<4HeY&YdpEI-zB+-ltbMJ<#Y@!_wRez>6uPPSBhwvB^u>$q z!(yzqb)iai_hp$DQf()4oaJ|AQXcLXiI&&fclVR@Nab>Spo{6`SyCRA+oNp1+@6|j zw9L0Av-(ClQi<*#7y782B&iC>4))@Bm%Ae1D_pNa_L|X1#~SSysLa<4JL452BRpsM zk6mWO>?vmpwC9m=B>FyOQdIm?_L+NXwO-(|7yJ{RhfR5p-Gce1C$e+W|uk`-y8+-qCwRd?%wb1*u zINtBIYqyvH)BfIU@A1=}xVGsUi@*`i>DIdoX22h|*C*#V2hW@fFv#1`YLOOioI&iy0f7IMNTC;K4|8gt zGFql?5vRyZYY;4pU80cM9Tpj!K#w8saZP}|e#lKy>|3Jg6HoLHbTRH@nMSsQA&o1D z6*$5zt~Vh`i7GEXatliKpzotX{ttKyBFqYKY7`rn2_mz?1 z{}_3lu{*o-_A{brpfvhoJ(37i5zHCc=(hDaxy9T;xS794YUMdOY^hLzNy~#D(U{E&~Hr{UDle{w$BCxjMn*22(2=L5eh;YON$< z#_Bca(d*b%?UXYFTkO-+0m5Z@oFOWQ<#d0di&T|m?dWM<2m48>2u-z{=)uc)<54mi zDY@6^*kGk^V7i`&+hhdGReA%GYjD%wh3pAZ86jhcuIr!_7w8IXDV#fytntkz1d;YD zen(z^8G`L*Wg$Zo#*mbAbTY zw76|~COB(XZsl15lR)DGAS#^w9fHuy2(JTD=wh9twSvG8-spZjzv<=e;t0M-6Z&<=8iZ)ln*Ntr4|lqcXVR%uhD$U9`_h?K0gzyEmG9%kY* zfOoU0J<9e^kQ2uO^H{kkwP|7Nq?i~dv((nk&rIPW+gw&yPK>qA$EJvdQ`0mv)=8Ex z9(LQeP`(VfTuAU>6{H9Od*7bKYuI(&cY6BXB--F2Jj1l6P+?Nc3`$CHs!C?`!*)a3 zeJA;4+$)>9YU*>YfnECO89X2t*pLUB!Ux`u`g3N3~V#(BX4GVhQ>%1YD<+xPv@fe8Ctp k))+m;fU(Z_=XVh;OovB#shi9k^T_QIA%w*v!Z2L@1Mq!*Qvd(} diff --git a/groupTasks/libs/utils/utils.py b/groupTasks/libs/utils/utils.py index 319dfb2..902d0ba 100644 --- a/groupTasks/libs/utils/utils.py +++ b/groupTasks/libs/utils/utils.py @@ -2,13 +2,23 @@ import subprocess import PyPDF2 import os import shutil +import sys + def clear_workspace(files): if not files or not isinstance(files, list) or len(files) == 0: return for file in files: - subprocess.run(["rm", file]) + if os.path.exists(file): + os.remove(file) + + +def delete_folder(folder_path): + try: + shutil.rmtree(folder_path) + except Exception as e: + print(f"Error deleting the folder {folder_path}: {e}") def merge_pdfs(pdf1_path, pdf2_path, output_path): @@ -42,4 +52,64 @@ def move_files_back_from_old_files(): 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 + os.rmdir("oldFiles") + + +# copy the tasks files from another task to the current runningTasks to execute it +# be aware of that in your work directory the python script has not the same name as the target script because it will be overwriten +def execute_another_group_task(folder_path, script_file_name): + work_directory = os.getcwd() # get current folder path + + copy_files(folder_path, work_directory) + clear_workspace(["index.json", "requirements.txt"]) + + execute_python_file(script_file_name) + + +def execute_python_file(file_path): + if not os.path.exists(file_path): + print(f"The file {file_path} does not exist.") + sys.exit(1) + return + + if not file_path.endswith('.py'): + print("The specified file is not a Python file.") + sys.exit(1) + return + + try: + #base_dir = os.path.dirname(os.path.abspath(file_path)) + #os.chdir(base_dir) # Change to the directory of the script + subprocess.run(['python3.9', os.path.basename(file_path)] + sys.argv[1:], check=True) + except subprocess.CalledProcessError as e: + print(f"Error executing the file: {e}") + sys.exit(1) + except Exception as e: + print(f"An unexpected error occurred: {e}") + sys.exit(1) + + +def copy_files(source_folder, destination_folder): + if not os.path.exists(source_folder): + print(f"The source folder {source_folder} does not exist.") + sys.exit(1) + return + + if not os.path.exists(destination_folder): + print(f"The destination folder {destination_folder} does not exist.") + sys.exit(1) + return + + try: + # List all files in the source folder + files = os.listdir(source_folder) + + # Copy each file to the destination folder + for file in files: + source_path = os.path.join(source_folder, file) + destination_path = os.path.join(destination_folder, file) + shutil.copy2(source_path, destination_path) + + except Exception as e: + print(f"An error occurred while copying files: {e}") + sys.exit(1) \ No newline at end of file