diff --git a/groupTasks/groups/shx-all-in-one-order/index.json b/groupTasks/groups/shx-all-in-one-order/index.json index a67dcaa..a0bf026 100644 --- a/groupTasks/groups/shx-all-in-one-order/index.json +++ b/groupTasks/groups/shx-all-in-one-order/index.json @@ -28,22 +28,30 @@ "type": "select", "displayName": "Produkttyp auswählen", "options": [ - "#32420; Gizmo_die Eidechse; Farbe; Grün, Blau, Orange; (Glänzend)", - "#92784; Gizmo_die Eidechse; Farbe; Glitzer Grün; (Seidenmatt)", - "#36521; Charlie_das Häschen; Farbe; Hellbraun; (Matt)", - "#48273; Charlie_das Häschen; Farbe; Gold; (Glänzend)", - "#71936; Ruby_die Schlange; Farbe; Feuerrot; (Glänzend)", - "#58324; Ruby_die Schlange; Farbe; Rot/Blau; (Glänzend)", - "#21433; Bruno_der Dino; Farbe; Grün/Blau/Orange; (Glänzend)", - "#57953; Bruno_der Dino; Farbe; Rot/Blau; (Glänzend)", - "#90578; Bruno_der Dino; Farbe; Gold; (Glänzend)", - "#51563; Bruno_der Dino; Farbe; Himmelblau; (Fluoreszierend)", - "#23564; Flamara_der Drache; Farbe; Feuerrot; (Glänzend)", - "#51139; Flamara_der Drache; Farbe; Himmelblau; (Fluoreszierend)", - "#77970; Flamara_der Drache; Farbe; Gold; (Glänzend)", - "#32974; Finn der_Sad Hamster; Stil; Standard; ", - "#60798; Finn der_Sad Hamster; Stil; Schlüsselanhänger; ", - "#93047; Mia_das Kätzchen; Farbe; Grau; " + "#32420 Gizmo die Eidechse, Farbe, Grün/Blau/Orange (Glänzend)", + "#83650 Gizmo die Eidechse, Farbe, Gold (Glänzend)", + "#92784 Gizmo die Eidechse, Farbe, Glitzer Grün (Seidenmatt)", + "#36521 Charlie das Häschen, Farbe, Hellbraun (Matt)", + "#48273 Charlie das Häschen, Farbe, Gold (Glänzend)", + "#71936 Ruby die Schlange, Farbe, Feuerrot (Glänzend)", + "#58324 Ruby die Schlange, Farbe, Rot/Blau (Glänzend)", + "#78648 Ruby die Schlange, Farbe, Gold (Glänzend)", + "#21433 Bruno der Dino, Farbe, Grün/Blau/Orange (Glänzend)", + "#57953 Bruno der Dino, Farbe, Rot/Blau (Glänzend)", + "#90578 Bruno der Dino, Farbe, Gold (Glänzend)", + "#51563 Bruno der Dino, Farbe, Himmelblau (Fluoreszierend)", + "#23564 Flamara der Drache, Farbe, Feuerrot (Glänzend)", + "#51139 Flamara der Drache, Farbe, Himmelblau (Fluoreszierend)", + "#77970 Flamara der Drache, Farbe, Gold (Glänzend)", + "#43356 Flamara der Drache, Farbe, Schwarz", + "#32974 Finn der Sad Hamster, Stil, Standard", + "#60798 Finn der Sad Hamster, Stil, Schlüsselanhänger", + "#30563 Finn der Sad Hamster, Größe, Groß", + "#93047 Mia das Kätzchen, Farbe, Grau", + "#56083 Hoppel das Häschen, Farbe, Grau", + "#78693 Elias der Corgi, Farbe, Braun/Weiß", + "#37335 Axel der Axolotl, Farbe, Pink", + "#26822 Dilo der Delfin, Farbe, Blau/Weiß" ] } ] @@ -102,4 +110,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/groupTasks/groups/shx-fetch-google-sheet-products/index.json b/groupTasks/groups/shx-fetch-google-sheet-products/index.json new file mode 100644 index 0000000..3ffd771 --- /dev/null +++ b/groupTasks/groups/shx-fetch-google-sheet-products/index.json @@ -0,0 +1,15 @@ +{ + "category": "Shinnex", + "name": "Produkte aus Google Sheets synchronisieren", + "globalInputs": [], + "tasks": [ + { + "name": "Produkte aus Google Sheets herunterladen", + "onFinish": "next", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "script.py", + "parameters": [] + } + ] +} \ No newline at end of file diff --git a/groupTasks/groups/shx-fetch-google-sheet-products/script.py b/groupTasks/groups/shx-fetch-google-sheet-products/script.py new file mode 100644 index 0000000..6f9dc1e --- /dev/null +++ b/groupTasks/groups/shx-fetch-google-sheet-products/script.py @@ -0,0 +1,84 @@ +import gspread +import json +import codecs + + +def add_underscore_at_position(text, position): + # Split the string into a list of words + words = text.split() + + # Check if the position is valid + if position < 0 or position >= len(words) - 1: + raise ValueError("Invalid position for underscore") + + # Add the underscore between the words at the specified position + words[position] = words[position] + '_' + words[position + 1] + + # Remove the word at the next position since it's already added + del words[position + 1] + + # Join the list back into a string + result = ' '.join(words) + + return result + + +# values by google sheets are returned like "Gold (Gl\u00e4nzend)" +def decode_unicode_escapes(text): + # Decode Unicode escape sequences + return codecs.decode(text, 'unicode_escape') + + +def update_grouptask_products_list_options(index_json_path, products_list): + with open(index_json_path, 'r', encoding='utf-8') as json_file: + data = json.load(json_file) + + options_list = [] + for product in products_list: + # replace _ with " " just for better style in dashboard + product_name = product['name'].replace("_", " ") + + option = f"#{product['id']} {product_name}, {product['product_variant']}, {product['product_color']}" + options_list.append(option) + + for task in data['tasks']: + for parameter in task['parameters']: + if parameter['parameterName'] == 'product_type_id': + parameter['options'] = options_list + + with open(index_json_path, 'w', encoding='utf-8') as output_file: + json.dump(data, output_file, ensure_ascii=False, indent=2) + + +def google_sheets_products(): + gc = gspread.service_account(filename="../../secrets/shinnex-424321-b88b144bc9ef.json") + + spreadsheet = gc.open("Produkte") + + worksheet = spreadsheet.get_worksheet(0) + + data = worksheet.get_all_values() + + products = [] + + for row in data[2:]: + products.append({ + "id": row[0], + "name": add_underscore_at_position(row[1], int(row[24])), + "product_variant": row[2], + "product_color": row[3] + }) + + products_dict = {"products": products} + + # Write the products list to a JSON file + with open('../../groupsData/google-sheet-products.json', 'w', encoding='utf-8') as json_file: + json.dump(products_dict, json_file, ensure_ascii=False, indent=2) + + update_grouptask_products_list_options("../../groups/shx-product-label/index.json", products) + update_grouptask_products_list_options("../../groups/shx-all-in-one-order/index.json", products) + + print("Finished. Do not forget to reload the group configuration") + + +google_sheets_products() \ No newline at end of file diff --git a/groupTasks/groups/shx-order-package-label/script.py b/groupTasks/groups/shx-order-package-label/script.py index 3e03598..a2a734f 100644 --- a/groupTasks/groups/shx-order-package-label/script.py +++ b/groupTasks/groups/shx-order-package-label/script.py @@ -108,6 +108,37 @@ def downloadFilePDF(url, filename): page.crop((0, spacing, page.width, h-spacing) ).save(filename, 'PNG') +def downloadFilePDFDHL(url, filename): + pdf_filename = filename + ".pdf" + + command = [ + "curl", + "-L", # Follow redirects + "-o", + pdf_filename, + url, + ] + + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = process.communicate() + + if process.returncode != 0: + print("Error downloading file") + print("STDOUT:") + print(stdout.decode()) # Decoding the stdout for better readability + print("STDERR:") + print(stderr.decode()) # Decoding the stderr for better readability + sys.exit(1) + + # Convert the PDF to a PNG + images = convert_from_path(pdf_filename, dpi=300) + + page = images[0] + + # box=(left, upper, right, lower) + #page.crop((0, spacing, page.width, h-spacing)).save(filename, 'PNG') + page.rotate(90, expand=1).save(filename, 'PNG') + def replacePlaceholder(): with open("index.html", "r") as file: @@ -125,7 +156,9 @@ if __name__ == "__main__": print(f"Creating package label for {customer_first_name}") #if shipping_label_url contains .pdf, download the file and convert it to a PNG - if ".pdf" in shipping_label_url or "https://cloud.umbach.dev/" in shipping_label_url: + if "247f81-22.myshopify.com" in shipping_label_url: + downloadFilePDFDHL(shipping_label_url, "label.png") + elif ".pdf" in shipping_label_url or "https://cloud.umbach.dev/" in shipping_label_url: downloadFilePDF(shipping_label_url, "label.png") else: downloadFilePNG(shipping_label_url, "label.png") diff --git a/groupTasks/groups/shx-product-label/index.html b/groupTasks/groups/shx-product-label/index.html index 5145502..86031a0 100644 --- a/groupTasks/groups/shx-product-label/index.html +++ b/groupTasks/groups/shx-product-label/index.html @@ -30,7 +30,7 @@ display: flex; justify-content: center; text-align: center; - /* border: 1px solid black; */ + border: 1px solid #fff; } .background-image { diff --git a/groupTasks/groups/shx-product-label/index.js b/groupTasks/groups/shx-product-label/index.js index 4509e14..6f05ad9 100644 --- a/groupTasks/groups/shx-product-label/index.js +++ b/groupTasks/groups/shx-product-label/index.js @@ -1,7 +1,7 @@ const PRODUCT_NAME = "{{PRODUCT_NAME}}", // Gizmo die Eidechse PRODUCT_VARIANT = "{{PRODUCT_VARIANT}}", // Farbe Grün/Blau/Orange or Stil Standard PRODUCT_COLOR_CHARACTERISTICS = "{{PRODUCT_COLOR_CHARACTERISTICS}}", // (Glänzend) - PRODUCT_ID = "{{PRODUCT_ID}}", // #32420 + PRODUCT_ID = "#{{PRODUCT_ID}}", // #32420 LABEL_PAPER_POSITION = "{{LABEL_PAPER_POSITION}}"; // could be a number between 1 and 12 or combination like 1,3,7 const labelPaperPosition = LABEL_PAPER_POSITION.split(","); diff --git a/groupTasks/groups/shx-product-label/index.json b/groupTasks/groups/shx-product-label/index.json index 10f5f9e..4b1e612 100644 --- a/groupTasks/groups/shx-product-label/index.json +++ b/groupTasks/groups/shx-product-label/index.json @@ -20,26 +20,34 @@ "type": "select", "displayName": "Produkttyp auswählen", "options": [ - "#32420; Gizmo_die Eidechse; Farbe; Grün, Blau, Orange; (Glänzend)", - "#92784; Gizmo_die Eidechse; Farbe; Glitzer Grün; (Seidenmatt)", - "#36521; Charlie_das Häschen; Farbe; Hellbraun; (Matt)", - "#48273; Charlie_das Häschen; Farbe; Gold; (Glänzend)", - "#71936; Ruby_die Schlange; Farbe; Feuerrot; (Glänzend)", - "#58324; Ruby_die Schlange; Farbe; Rot/Blau; (Glänzend)", - "#21433; Bruno_der Dino; Farbe; Grün/Blau/Orange; (Glänzend)", - "#57953; Bruno_der Dino; Farbe; Rot/Blau; (Glänzend)", - "#90578; Bruno_der Dino; Farbe; Gold; (Glänzend)", - "#51563; Bruno_der Dino; Farbe; Himmelblau; (Fluoreszierend)", - "#23564; Flamara_der Drache; Farbe; Feuerrot; (Glänzend)", - "#51139; Flamara_der Drache; Farbe; Himmelblau; (Fluoreszierend)", - "#77970; Flamara_der Drache; Farbe; Gold; (Glänzend)", - "#32974; Finn der_Sad Hamster; Stil; Standard; ", - "#60798; Finn der_Sad Hamster; Stil; Schlüsselanhänger; ", - "#93047; Mia_das Kätzchen; Farbe; Grau; " + "#32420 Gizmo die Eidechse, Farbe, Grün/Blau/Orange (Glänzend)", + "#83650 Gizmo die Eidechse, Farbe, Gold (Glänzend)", + "#92784 Gizmo die Eidechse, Farbe, Glitzer Grün (Seidenmatt)", + "#36521 Charlie das Häschen, Farbe, Hellbraun (Matt)", + "#48273 Charlie das Häschen, Farbe, Gold (Glänzend)", + "#71936 Ruby die Schlange, Farbe, Feuerrot (Glänzend)", + "#58324 Ruby die Schlange, Farbe, Rot/Blau (Glänzend)", + "#78648 Ruby die Schlange, Farbe, Gold (Glänzend)", + "#21433 Bruno der Dino, Farbe, Grün/Blau/Orange (Glänzend)", + "#57953 Bruno der Dino, Farbe, Rot/Blau (Glänzend)", + "#90578 Bruno der Dino, Farbe, Gold (Glänzend)", + "#51563 Bruno der Dino, Farbe, Himmelblau (Fluoreszierend)", + "#23564 Flamara der Drache, Farbe, Feuerrot (Glänzend)", + "#51139 Flamara der Drache, Farbe, Himmelblau (Fluoreszierend)", + "#77970 Flamara der Drache, Farbe, Gold (Glänzend)", + "#43356 Flamara der Drache, Farbe, Schwarz", + "#32974 Finn der Sad Hamster, Stil, Standard", + "#60798 Finn der Sad Hamster, Stil, Schlüsselanhänger", + "#30563 Finn der Sad Hamster, Größe, Groß", + "#93047 Mia das Kätzchen, Farbe, Grau", + "#56083 Hoppel das Häschen, Farbe, Grau", + "#78693 Elias der Corgi, Farbe, Braun/Weiß", + "#37335 Axel der Axolotl, Farbe, Pink", + "#26822 Dilo der Delfin, Farbe, Blau/Weiß" ], "global": false } ] } ] -} +} \ No newline at end of file diff --git a/groupTasks/groups/shx-product-label/script.py b/groupTasks/groups/shx-product-label/script.py index 92488b4..179452e 100644 --- a/groupTasks/groups/shx-product-label/script.py +++ b/groupTasks/groups/shx-product-label/script.py @@ -18,7 +18,7 @@ if product_type_id is None or label_paper_position is None: product_type_id = product_type_id["value"] label_paper_position = label_paper_position["value"] - +""" product_type_ids = {} def add_product_type_id(product_type_id, product_name, product_variant, product_color_characteristics): @@ -38,7 +38,7 @@ for product in products: data = product.split("; ") # remove the # on the start - add_product_type_id(data[0][1:], data[1], data[2] + " " + data[3], data[4]) + add_product_type_id(data[0][1:], data[1], data[2] + " " + data[3], data[4]) """ def createPdf(sourceHtml, outputPdf): command = [ @@ -63,10 +63,44 @@ def createPdf(sourceHtml, outputPdf): if __name__ == "__main__": utils.move_files_back_from_old_files() - # remove the ; on the end of the id # replace placeholders in index.js - p_type_id = product_type_id.split(" ")[0].split("#")[1][:-1] + p_type_id = product_type_id.split(" ")[0].split("#")[1] + + print(f"Creating product label for product type #{p_type_id}") + + with open('../../groupsData/google-sheet-products.json', 'r', encoding='utf-8') as json_file: + data = json.load(json_file) + + for product in data["products"]: + if product["id"] == p_type_id: + with open("index.js", "r") as file: + indexjs = file.read() + + product_color_characteristics = "" + + if product["product_variant"] != "Farbe": + product_variant = product["product_variant"] + " " + product["product_color"] + else: + product_color_splitted = product["product_color"].split(" ") + + product_variant = product["product_variant"] + " " + product_color_splitted[0] + + if len(product_color_splitted) > 1: + product_color_characteristics = product_color_splitted[1] + + indexjs = indexjs.replace("{{PRODUCT_ID}}", product["id"]) + indexjs = indexjs.replace("{{PRODUCT_NAME}}", product["name"]) + indexjs = indexjs.replace("{{PRODUCT_VARIANT}}", product_variant) + indexjs = indexjs.replace("{{PRODUCT_COLOR_CHARACTERISTICS}}", product_color_characteristics) + indexjs = indexjs.replace("{{LABEL_PAPER_POSITION}}", label_paper_position) + + with open("index.js", "w") as file: + file.write(indexjs) + + break + + """ if p_type_id not in product_type_ids: print("Product type not found") sys.exit(1) @@ -86,6 +120,7 @@ if __name__ == "__main__": with open("index.js", "w") as file: file.write(indexjs) + """ # create front page diff --git a/groupTasks/groupsData/google-sheet-products.json b/groupTasks/groupsData/google-sheet-products.json new file mode 100644 index 0000000..060937b --- /dev/null +++ b/groupTasks/groupsData/google-sheet-products.json @@ -0,0 +1,148 @@ +{ + "products": [ + { + "id": "32420", + "name": "Gizmo_die Eidechse", + "product_variant": "Farbe", + "product_color": "Grün/Blau/Orange (Glänzend)" + }, + { + "id": "83650", + "name": "Gizmo_die Eidechse", + "product_variant": "Farbe", + "product_color": "Gold (Glänzend)" + }, + { + "id": "92784", + "name": "Gizmo_die Eidechse", + "product_variant": "Farbe", + "product_color": "Glitzer Grün (Seidenmatt)" + }, + { + "id": "36521", + "name": "Charlie_das Häschen", + "product_variant": "Farbe", + "product_color": "Hellbraun (Matt)" + }, + { + "id": "48273", + "name": "Charlie_das Häschen", + "product_variant": "Farbe", + "product_color": "Gold (Glänzend)" + }, + { + "id": "71936", + "name": "Ruby_die Schlange", + "product_variant": "Farbe", + "product_color": "Feuerrot (Glänzend)" + }, + { + "id": "58324", + "name": "Ruby_die Schlange", + "product_variant": "Farbe", + "product_color": "Rot/Blau (Glänzend)" + }, + { + "id": "78648", + "name": "Ruby_die Schlange", + "product_variant": "Farbe", + "product_color": "Gold (Glänzend)" + }, + { + "id": "21433", + "name": "Bruno_der Dino", + "product_variant": "Farbe", + "product_color": "Grün/Blau/Orange (Glänzend)" + }, + { + "id": "57953", + "name": "Bruno_der Dino", + "product_variant": "Farbe", + "product_color": "Rot/Blau (Glänzend)" + }, + { + "id": "90578", + "name": "Bruno_der Dino", + "product_variant": "Farbe", + "product_color": "Gold (Glänzend)" + }, + { + "id": "51563", + "name": "Bruno_der Dino", + "product_variant": "Farbe", + "product_color": "Himmelblau (Fluoreszierend)" + }, + { + "id": "23564", + "name": "Flamara_der Drache", + "product_variant": "Farbe", + "product_color": "Feuerrot (Glänzend)" + }, + { + "id": "51139", + "name": "Flamara_der Drache", + "product_variant": "Farbe", + "product_color": "Himmelblau (Fluoreszierend)" + }, + { + "id": "77970", + "name": "Flamara_der Drache", + "product_variant": "Farbe", + "product_color": "Gold (Glänzend)" + }, + { + "id": "43356", + "name": "Flamara_der Drache", + "product_variant": "Farbe", + "product_color": "Schwarz" + }, + { + "id": "32974", + "name": "Finn der_Sad Hamster", + "product_variant": "Stil", + "product_color": "Standard" + }, + { + "id": "60798", + "name": "Finn der_Sad Hamster", + "product_variant": "Stil", + "product_color": "Schlüsselanhänger" + }, + { + "id": "30563", + "name": "Finn der_Sad Hamster", + "product_variant": "Größe", + "product_color": "Groß" + }, + { + "id": "93047", + "name": "Mia_das Kätzchen", + "product_variant": "Farbe", + "product_color": "Grau" + }, + { + "id": "56083", + "name": "Hoppel_das Häschen", + "product_variant": "Farbe", + "product_color": "Grau" + }, + { + "id": "78693", + "name": "Elias_der Corgi", + "product_variant": "Farbe", + "product_color": "Braun/Weiß" + }, + { + "id": "37335", + "name": "Axel_der Axolotl", + "product_variant": "Farbe", + "product_color": "Pink" + }, + { + "id": "26822", + "name": "Dilo_der Delfin", + "product_variant": "Farbe", + "product_color": "Blau/Weiß" + } + ] +} \ No newline at end of file diff --git a/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc b/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc index 293fc64..a8b5f5f 100644 Binary files a/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc and b/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc differ