filament roll label
parent
73816eaca5
commit
836575a395
|
@ -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,
|
|
@ -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()
|
|
@ -0,0 +1,104 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Intern Filament Roll Label</title>
|
||||
<style>
|
||||
:root {
|
||||
--container-width: 1020px;
|
||||
--container-height: 400px;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Outfit";
|
||||
src: url("../../groupsData/static/Outfit-VariableFont_wght.ttf");
|
||||
}
|
||||
|
||||
body,
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 14px;
|
||||
width: var(--container-width);
|
||||
height: var(--container-height);
|
||||
overflow: hidden;
|
||||
font-family: "Outfit";
|
||||
}
|
||||
|
||||
.container {
|
||||
width: var(--container-width);
|
||||
height: var(--container-height);
|
||||
}
|
||||
|
||||
.inner-container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="inner-container">
|
||||
<div
|
||||
style="
|
||||
width: 620px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
"
|
||||
>
|
||||
<div>
|
||||
<div style="display: flex; justify-content: space-between">
|
||||
<div style="display: flex; align-items: center; gap: 20px">
|
||||
<img
|
||||
src="../../groupsData/shx-intern-filament-roll-label/filament-roll.png"
|
||||
style="width: 160px"
|
||||
/>
|
||||
|
||||
<h1 style="font-size: 128px; font-weight: 500">
|
||||
{{FILAMENT_ID}}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<img
|
||||
src="../../groupsData/shx-intern-filament-roll-label/logo.svg"
|
||||
style="width: 120px; padding-right: 10px"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style="padding-top: 10px; padding-left: 20px">
|
||||
<h1 style="font-size: 48px; font-weight: 600">
|
||||
{{FILAMENT_NAME_COLOR}}
|
||||
</h1>
|
||||
<h1 style="font-size: 48px; font-weight: 400">
|
||||
{{FILAMENT_MATERIAL}}
|
||||
</h1>
|
||||
<h1 style="font-size: 48px; font-weight: 400">
|
||||
{{FILAMENT_MANUFACTURER}}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span
|
||||
style="
|
||||
font-size: 20px;
|
||||
text-align: right;
|
||||
padding-right: 20px;
|
||||
padding-bottom: 20px;
|
||||
"
|
||||
>{{DATE}}</span
|
||||
>
|
||||
</div>
|
||||
|
||||
<div style="padding: 20px">
|
||||
<img src="qrcode.png" style="width: 360px" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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"])
|
|
@ -36,7 +36,6 @@
|
|||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
h3 {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 177 KiB |
Binary file not shown.
|
@ -79,7 +79,8 @@ def execute_python_file(file_path):
|
|||
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)
|
||||
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)
|
||||
|
@ -117,6 +118,11 @@ def extract_product_id(product_type_id):
|
|||
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):
|
||||
data = qr_code_url
|
||||
|
||||
|
|
Loading…
Reference in New Issue