diff --git a/groupTasks/groups/shx-fetch-google-sheet-products/index.json b/groupTasks/groups/shx-fetch-google-sheet-data/index.json similarity index 65% rename from groupTasks/groups/shx-fetch-google-sheet-products/index.json rename to groupTasks/groups/shx-fetch-google-sheet-data/index.json index 3ffd771..dfdba55 100644 --- a/groupTasks/groups/shx-fetch-google-sheet-products/index.json +++ b/groupTasks/groups/shx-fetch-google-sheet-data/index.json @@ -1,10 +1,10 @@ { "category": "Shinnex", - "name": "Produkte aus Google Sheets synchronisieren", + "name": "Daten aus Google Sheets synchronisieren", "globalInputs": [], "tasks": [ { - "name": "Produkte aus Google Sheets herunterladen", + "name": "Daten aus Google Sheets synchronisieren", "onFinish": "next", "undoPossible": false, "repeatPossible": true, diff --git a/groupTasks/groups/shx-fetch-google-sheet-products/script.py b/groupTasks/groups/shx-fetch-google-sheet-data/script.py similarity index 56% rename from groupTasks/groups/shx-fetch-google-sheet-products/script.py rename to groupTasks/groups/shx-fetch-google-sheet-data/script.py index 4a3a8f7..8577de8 100644 --- a/groupTasks/groups/shx-fetch-google-sheet-products/script.py +++ b/groupTasks/groups/shx-fetch-google-sheet-data/script.py @@ -3,6 +3,11 @@ import json import codecs import sys +SERVICE_ACCOUNT_FILENAME = "../../secrets/shinnex-424321-b88b144bc9ef.json" +GOOGLE_SPEADSHEET_KEY = "1gZkjykb55aLWumBxHxj_ZUq_ktjGK4FlJsH_9qg-ThU" # from url +WORKSHEET_PRODUCTS = "Produkte" +WORKSHEET_FILAMENTS = "Filamente" + def add_underscore_at_position(text, position): # Split the string into a list of words @@ -56,20 +61,38 @@ def update_grouptask_products_list_options(index_json_path, products_list): json.dump(data, output_file, ensure_ascii=False, indent=2) +def update_grouptask_filaments_list_options(index_json_path, filaments_list): + with open(index_json_path, 'r', encoding='utf-8') as json_file: + data = json.load(json_file) + + options_list = [] + + for filament in filaments_list: + option = f"{filament['id']} {filament['name_color']}, {filament['material']}, {filament['manufacturer']}" + options_list.append(option) + + for task in data['tasks']: + for parameter in task['parameters']: + if parameter['parameterName'] == 'filament_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") + gc = gspread.service_account(filename=SERVICE_ACCOUNT_FILENAME) - spreadsheet = gc.open_by_key( - "1gZkjykb55aLWumBxHxj_ZUq_ktjGK4FlJsH_9qg-ThU") + spreadsheet = gc.open_by_key(GOOGLE_SPEADSHEET_KEY) - worksheet = spreadsheet.worksheet("Produkte") + worksheet = spreadsheet.worksheet(WORKSHEET_PRODUCTS) data = worksheet.get_all_values() # auto get the row index numbers for the columns products = [] + rowIndexProductId = -1 rowIndexProductName = -1 rowIndexProductVariant = -1 @@ -94,7 +117,8 @@ def google_sheets_products(): rowIndexNameSplitAtPosition = i if rowIndexProductId == -1 or rowIndexProductId == -1 or rowIndexProductName == -1 or rowIndexProductVariant == -1 or rowIndexProductCharacteristicLine1 == -1 or rowIndexProductCharacteristicLine2 == -1: - sys.exit("Failed to get row index. Please check if the row names are equal to the names of the google sheet table header") + sys.exit( + f"Failed to get row index. Please check if the row names are equal to the names of the google sheet table header of {WORKSHEET_PRODUCTS}") # adding products to list @@ -112,7 +136,7 @@ def google_sheets_products(): products_dict = {"products": products} - # Write the products list to a JSON file + # 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) @@ -124,4 +148,62 @@ def google_sheets_products(): print("Finished. Do not forget to reload the group configuration by clicking on the 'Reload' button above the table on the right side.") +def google_sheets_filaments(): + gc = gspread.service_account(filename=SERVICE_ACCOUNT_FILENAME) + + spreadsheet = gc.open_by_key(GOOGLE_SPEADSHEET_KEY) + + worksheet = spreadsheet.worksheet(WORKSHEET_FILAMENTS) + + data = worksheet.get_all_values() + + # auto get the row index numbers for the columns + + filaments = [] + + rowIndexFilamentId = -1 + rowIndexFilamentNameColor = -1 + rowIndexFilamentMaterial = -1 + rowIndexFilamentManufacturer = -1 + + for i in range(len(data[0])): + row = data[0][i] + + if row == "id": + rowIndexFilamentId = i + elif row == "Name/Farbe": + rowIndexFilamentNameColor = i + elif row == "Material": + rowIndexFilamentMaterial = i + elif row == "Hersteller": + rowIndexFilamentManufacturer = i + + if rowIndexFilamentId == -1 or rowIndexFilamentNameColor == -1 or rowIndexFilamentMaterial == -1 or rowIndexFilamentManufacturer == -1: + sys.exit( + f"Failed to get row index. Please check if the row names are equal to the names of the google sheet table header of {WORKSHEET_FILAMENTS}") + + # adding filaments to list + + for row in data[2:]: + if row[0] == "": + continue + + filaments.append({ + "id": row[rowIndexFilamentId], + "name_color": row[rowIndexFilamentNameColor], + "material": row[rowIndexFilamentMaterial], + "manufacturer": row[rowIndexFilamentManufacturer] + }) + + filaments_dict = {"filaments": filaments} + + # write the filaments list to a JSON file + with open('../../groupsData/google-sheet-filaments.json', 'w', encoding='utf-8') as json_file: + json.dump(filaments_dict, json_file, ensure_ascii=False, indent=2) + + update_grouptask_filaments_list_options( + "../../groups/shx-intern-filament-roll-label/index.json", filaments) + + google_sheets_products() +google_sheets_filaments() diff --git a/groupTasks/groups/shx-intern-filament-roll-label/index.html b/groupTasks/groups/shx-intern-filament-roll-label/index.html new file mode 100644 index 0000000..cd7e074 --- /dev/null +++ b/groupTasks/groups/shx-intern-filament-roll-label/index.html @@ -0,0 +1,104 @@ + + + + + + Intern Filament Roll Label + + + +
+
+
+
+
+
+ + +

+ {{FILAMENT_ID}} +

+
+ + +
+ +
+

+ {{FILAMENT_NAME_COLOR}} +

+

+ {{FILAMENT_MATERIAL}} +

+

+ {{FILAMENT_MANUFACTURER}} +

+
+
+ + {{DATE}} +
+ +
+ +
+
+
+ + diff --git a/groupTasks/groups/shx-intern-filament-roll-label/index.json b/groupTasks/groups/shx-intern-filament-roll-label/index.json new file mode 100644 index 0000000..7ca04a7 --- /dev/null +++ b/groupTasks/groups/shx-intern-filament-roll-label/index.json @@ -0,0 +1,42 @@ +{ + "category": "Shinnex", + "name": "Internes Etikett für Filamentrolle", + "globalInputs": [], + "tasks": [ + { + "name": "Internes Etikett für Filamentrolle erstellen", + "onFinish": "next", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "script.py", + "parameters": [ + { + "parameterName": "filament_type_id", + "type": "select", + "displayName": "Filament auswählen", + "global": false, + "options": [ + "11 Weiß, Matte PLA, OVERTURE", + "12 Gold, Silk PLA, OVERTURE", + "13 Rot, Silk PLA, OVERTURE", + "14 Holzfarbe, Matte PLA, OVERTURE", + "15 Rot/Blau, Dual-Color Silk PLA, ERYONE", + "16 Orange/Blau/Grün, Tri-Color Silk PLA, TRONXY", + "17 Blau, Fluorescent PLA, ZIRO", + "18 Orange, Fluorescent PLA, ZIRO", + "19 Diamant-Smaragdgrün, Glitter PLA, ZIRO", + "20 Schwarz Glänzend, Silk PLA, SUNLU", + "21 Rosa, Matte PLA, OVERTURE", + "22 Hellgrau, Matte PLA, OVERTURE", + "23 Schokolade, Matte PLA, OVERTURE", + "24 Rosa/Weiß, Silk PLA, SUNLU", + "25 Blau/Weiß, TempChange Matte PLA, TRONXY", + "26 Beige, Matte PLA, OVERTURE", + "27 Marineblau, Matte PLA, OVERTURE", + "28 Gelb, Matte PLA, OVERTURE" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/groupTasks/groups/shx-intern-filament-roll-label/script.py b/groupTasks/groups/shx-intern-filament-roll-label/script.py new file mode 100644 index 0000000..d8445a3 --- /dev/null +++ b/groupTasks/groups/shx-intern-filament-roll-label/script.py @@ -0,0 +1,85 @@ +import json +import subprocess +import sys +import os +from datetime import datetime + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) + +from libs.utils import utils + +json_object = json.loads(sys.argv[1]) +filament_type_id = json_object["filament_type_id"] + +if filament_type_id is None: + print("Missing required parameters") + sys.exit(1) + +filament_type_id = filament_type_id["value"] + +def createHighDpiPng(sourceHtml, outputPng): + # Calculate scaled dimensions + scale_factor = 1 + width = int(1020 * scale_factor) # Original width in pixels multiplied by the scale factor + height = int(400 * scale_factor) # Original height in pixels multiplied by the scale factor + + command = [ + "google-chrome-stable", + "--headless", + "--no-sandbox", + "--disable-gpu", + "--screenshot=" + outputPng, + "--window-size={},{}".format(width, height), # Set window size to scaled dimensions + "--force-device-scale-factor={}".format(scale_factor), # Set device scale factor + sourceHtml, + ] + + process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + _, stderr = process.communicate() + + if process.returncode != 0: + print("Error creating PNG") + print(stderr.decode()) # Decoding the stderr for better readability + sys.exit(1) + + +if __name__ == "__main__": + utils.move_files_back_from_old_files() + + # replace placeholders in index.html + f_type_id = utils.extract_filament_id(filament_type_id) + + data = { + "invex_id": "", + "shx_filament_id": f_type_id + } + + utils.create_qrcode(json.dumps(data), "./qrcode.png", "#fff") + + with open('../../groupsData/google-sheet-filaments.json', 'r', encoding='utf-8') as json_file: + data = json.load(json_file) + + for filament in data["filaments"]: + if filament["id"] == f_type_id: + with open("index.html", "r") as file: + indexhtml = file.read() + + indexhtml = indexhtml.replace("{{FILAMENT_ID}}", filament["id"]) + indexhtml = indexhtml.replace("{{FILAMENT_NAME_COLOR}}", filament["name_color"]) + indexhtml = indexhtml.replace("{{FILAMENT_MATERIAL}}", filament["material"]) + indexhtml = indexhtml.replace("{{FILAMENT_MANUFACTURER}}", filament["manufacturer"]) + + now = datetime.now() + formatted_date = now.strftime("%d.%m.%Y") + + indexhtml = indexhtml.replace("{{DATE}}", formatted_date) + + with open("index.html", "w") as file: + file.write(indexhtml) + + break + + + createHighDpiPng("index.html", "filament-roll-label.png") + + utils.clear_workspace(["index.html", "qrcode.png"]) \ No newline at end of file diff --git a/groupTasks/groups/shx-intern-product-bag-label/index.html b/groupTasks/groups/shx-intern-product-bag-label/index.html index cf677d0..d84ad8f 100644 --- a/groupTasks/groups/shx-intern-product-bag-label/index.html +++ b/groupTasks/groups/shx-intern-product-bag-label/index.html @@ -36,7 +36,6 @@ display: flex; flex-direction: column; justify-content: space-between; - height: 100%; } h3 { diff --git a/groupTasks/groupsData/google-sheet-filaments.json b/groupTasks/groupsData/google-sheet-filaments.json new file mode 100644 index 0000000..4b67f29 --- /dev/null +++ b/groupTasks/groupsData/google-sheet-filaments.json @@ -0,0 +1,112 @@ +{ + "filaments": [ + { + "id": "11", + "name_color": "Weiß", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "12", + "name_color": "Gold", + "material": "Silk PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "13", + "name_color": "Rot", + "material": "Silk PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "14", + "name_color": "Holzfarbe", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "15", + "name_color": "Rot/Blau", + "material": "Dual-Color Silk PLA", + "manufacturer": "ERYONE" + }, + { + "id": "16", + "name_color": "Orange/Blau/Grün", + "material": "Tri-Color Silk PLA", + "manufacturer": "TRONXY" + }, + { + "id": "17", + "name_color": "Blau", + "material": "Fluorescent PLA", + "manufacturer": "ZIRO" + }, + { + "id": "18", + "name_color": "Orange", + "material": "Fluorescent PLA", + "manufacturer": "ZIRO" + }, + { + "id": "19", + "name_color": "Diamant-Smaragdgrün", + "material": "Glitter PLA", + "manufacturer": "ZIRO" + }, + { + "id": "20", + "name_color": "Schwarz Glänzend", + "material": "Silk PLA", + "manufacturer": "SUNLU" + }, + { + "id": "21", + "name_color": "Rosa", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "22", + "name_color": "Hellgrau", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "23", + "name_color": "Schokolade", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "24", + "name_color": "Rosa/Weiß", + "material": "Silk PLA", + "manufacturer": "SUNLU" + }, + { + "id": "25", + "name_color": "Blau/Weiß", + "material": "TempChange Matte PLA", + "manufacturer": "TRONXY" + }, + { + "id": "26", + "name_color": "Beige", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "27", + "name_color": "Marineblau", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + }, + { + "id": "28", + "name_color": "Gelb", + "material": "Matte PLA", + "manufacturer": "OVERTURE" + } + ] +} \ No newline at end of file diff --git a/groupTasks/groupsData/shx-intern-filament-roll-label/filament-roll.png b/groupTasks/groupsData/shx-intern-filament-roll-label/filament-roll.png new file mode 100644 index 0000000..40fccd2 Binary files /dev/null and b/groupTasks/groupsData/shx-intern-filament-roll-label/filament-roll.png differ diff --git a/groupTasks/groupsData/shx-intern-filament-roll-label/logo.svg b/groupTasks/groupsData/shx-intern-filament-roll-label/logo.svg new file mode 100644 index 0000000..7c07479 --- /dev/null +++ b/groupTasks/groupsData/shx-intern-filament-roll-label/logo.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc b/groupTasks/libs/utils/__pycache__/utils.cpython-39.pyc index f36f72e..fb84667 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 3effe58..9158e9a 100644 --- a/groupTasks/libs/utils/utils.py +++ b/groupTasks/libs/utils/utils.py @@ -9,42 +9,42 @@ import qrcode def clear_workspace(files): if not files or not isinstance(files, list) or len(files) == 0: return - + for file in files: 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}") + 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): - # open the two PDF files - with open(pdf1_path, 'rb') as file1, open(pdf2_path, 'rb') as file2: - # create PDF-Reader-Objects - pdf1_reader = PyPDF2.PdfReader(file1) - pdf2_reader = PyPDF2.PdfReader(file2) - - # create PDF-Writer-Object - pdf_writer = PyPDF2.PdfWriter() - - # add pages from the first PDF - for page_num in range(len(pdf1_reader.pages)): - page = pdf1_reader.pages[page_num] - pdf_writer.add_page(page) - - # add pages from the second PDF - for page_num in range(len(pdf2_reader.pages)): - page = pdf2_reader.pages[page_num] - pdf_writer.add_page(page) - - # save the combined PDF - with open(output_path, 'wb') as output_file: - pdf_writer.write(output_file) + # open the two PDF files + with open(pdf1_path, 'rb') as file1, open(pdf2_path, 'rb') as file2: + # create PDF-Reader-Objects + pdf1_reader = PyPDF2.PdfReader(file1) + pdf2_reader = PyPDF2.PdfReader(file2) + + # create PDF-Writer-Object + pdf_writer = PyPDF2.PdfWriter() + + # add pages from the first PDF + for page_num in range(len(pdf1_reader.pages)): + page = pdf1_reader.pages[page_num] + pdf_writer.add_page(page) + + # add pages from the second PDF + for page_num in range(len(pdf2_reader.pages)): + page = pdf2_reader.pages[page_num] + pdf_writer.add_page(page) + + # save the combined PDF + with open(output_path, 'wb') as output_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 @@ -59,7 +59,7 @@ def move_files_back_from_old_files(): # 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 + work_directory = os.getcwd() # get current folder path copy_files(folder_path, work_directory) clear_workspace(["index.json", "requirements.txt"]) @@ -77,9 +77,10 @@ def execute_python_file(file_path): sys.exit(1) 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) + # 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) @@ -92,21 +93,21 @@ 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) - + if not os.path.exists(destination_folder): print(f"The destination folder {destination_folder} does not exist.") sys.exit(1) - + 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) @@ -114,7 +115,12 @@ def copy_files(source_folder, destination_folder): # this will extract the product id from the string which is provided as arg from the select dropdown where the user can select a product def extract_product_id(product_type_id): - return product_type_id.split(" ")[0].split("#")[1] + return product_type_id.split(" ")[0].split("#")[1] + + +def extract_filament_id(filament_type_id): + print("extract_filament_id", filament_type_id) + return filament_type_id.split(" ")[0] def create_qrcode(qr_code_url, save_path, back_color): @@ -135,4 +141,4 @@ def create_qrcode(qr_code_url, save_path, back_color): # Save image to a file # like ./test.png - img.save(save_path) \ No newline at end of file + img.save(save_path)