From 8fb9d31dddfd4aee8ea08f4866e9076c466d58f8 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 20 Jun 2024 19:07:42 +0200 Subject: [PATCH] auto generate discount code --- .../groups/shx-all-in-one-order/index.json | 21 +++-- .../shx-intern-filament-roll-label/index.json | 3 +- .../shx-intern-product-bag-label/index.json | 14 ++- .../groups/shx-new-product-steps/empty.py | 0 .../groups/shx-new-product-steps/index.json | 87 ++++++++++++++++++ .../groups/shx-order-voucher-codes/index.json | 7 +- .../groups/shx-order-voucher-codes/script.py | 59 +++++++++++- .../groups/shx-product-label/index.json | 14 ++- .../groupsData/google-sheet-filaments.json | 6 ++ .../groupsData/google-sheet-products.json | 62 ++++++++++++- .../utils/__pycache__/utils.cpython-39.pyc | Bin 3815 -> 4036 bytes groupTasks/libs/utils/utils.py | 6 ++ 12 files changed, 249 insertions(+), 30 deletions(-) create mode 100644 groupTasks/groups/shx-new-product-steps/empty.py create mode 100644 groupTasks/groups/shx-new-product-steps/index.json diff --git a/groupTasks/groups/shx-all-in-one-order/index.json b/groupTasks/groups/shx-all-in-one-order/index.json index b61b951..0994a9b 100644 --- a/groupTasks/groups/shx-all-in-one-order/index.json +++ b/groupTasks/groups/shx-all-in-one-order/index.json @@ -42,8 +42,11 @@ "#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)", + "#58324 Ruby die Schlange, FARBE, Lila/Blau, (Glänzend)", "#78648 Ruby die Schlange, FARBE, Gold, (Glänzend)", + "#15809 Ruby die Schlange, FARBE, Himmelblau, (Fluoreszierend)", + "#49461 Ruby die Schlange, FARBE, Rosa, (Matt)", + "#84491 Ruby die Schlange, FARBE, Rot/Schwarz, (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)", @@ -69,14 +72,19 @@ "#35717 Stella der Phönix, FARBE, Sonderanfertigung, Rosa/Weiß", "#26843 Stella der Phönix, FARBE, Verlauf Lila/Pink, ", "#74943 Brain der Fuchs, STIL, Standard, ", - "#78071 Weißer Hund, STIL, Weiß, ", - "#92734 Amigo der Capybara, FARBE, Braun, " + "#78071 Lucky der Barsoi, FARBE, Weiß, ", + "#92734 Amigo der Capybara, FARBE, Braun, ", + "#22318 Witty der Fuchs, STIL, Standard, ", + "#23732 Witty der Fuchs, STIL, Standard, Mit Halstuch", + "#72175 Paco die Bulldogge, FARBE, Grau, ", + "#55172 Sharky der Hai, FARBE, Grau, ", + "#10971 Chibi die Ratte, FARBE, Grau, " ] } ] }, { - "name": "Gutscheincodes für Bestellung erstellen (nur die Bestellnummer ohne #)", + "name": "Gutscheincodes für Bestellung erstellen", "onFinish": "pause", "undoPossible": false, "repeatPossible": true, @@ -101,11 +109,6 @@ "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)" } ] }, diff --git a/groupTasks/groups/shx-intern-filament-roll-label/index.json b/groupTasks/groups/shx-intern-filament-roll-label/index.json index 7ca04a7..a3f6de0 100644 --- a/groupTasks/groups/shx-intern-filament-roll-label/index.json +++ b/groupTasks/groups/shx-intern-filament-roll-label/index.json @@ -33,7 +33,8 @@ "25 Blau/Weiß, TempChange Matte PLA, TRONXY", "26 Beige, Matte PLA, OVERTURE", "27 Marineblau, Matte PLA, OVERTURE", - "28 Gelb, Matte PLA, OVERTURE" + "28 Gelb, Matte PLA, OVERTURE", + "29 Rot/Schwarz, Dual-Color Silk PLA, AMOLEN" ] } ] diff --git a/groupTasks/groups/shx-intern-product-bag-label/index.json b/groupTasks/groups/shx-intern-product-bag-label/index.json index e2249d6..0c4e22c 100644 --- a/groupTasks/groups/shx-intern-product-bag-label/index.json +++ b/groupTasks/groups/shx-intern-product-bag-label/index.json @@ -22,8 +22,11 @@ "#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)", + "#58324 Ruby die Schlange, FARBE, Lila/Blau, (Glänzend)", "#78648 Ruby die Schlange, FARBE, Gold, (Glänzend)", + "#15809 Ruby die Schlange, FARBE, Himmelblau, (Fluoreszierend)", + "#49461 Ruby die Schlange, FARBE, Rosa, (Matt)", + "#84491 Ruby die Schlange, FARBE, Rot/Schwarz, (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)", @@ -49,8 +52,13 @@ "#35717 Stella der Phönix, FARBE, Sonderanfertigung, Rosa/Weiß", "#26843 Stella der Phönix, FARBE, Verlauf Lila/Pink, ", "#74943 Brain der Fuchs, STIL, Standard, ", - "#78071 Weißer Hund, STIL, Weiß, ", - "#92734 Amigo der Capybara, FARBE, Braun, " + "#78071 Lucky der Barsoi, FARBE, Weiß, ", + "#92734 Amigo der Capybara, FARBE, Braun, ", + "#22318 Witty der Fuchs, STIL, Standard, ", + "#23732 Witty der Fuchs, STIL, Standard, Mit Halstuch", + "#72175 Paco die Bulldogge, FARBE, Grau, ", + "#55172 Sharky der Hai, FARBE, Grau, ", + "#10971 Chibi die Ratte, FARBE, Grau, " ] } ] diff --git a/groupTasks/groups/shx-new-product-steps/empty.py b/groupTasks/groups/shx-new-product-steps/empty.py new file mode 100644 index 0000000..e69de29 diff --git a/groupTasks/groups/shx-new-product-steps/index.json b/groupTasks/groups/shx-new-product-steps/index.json new file mode 100644 index 0000000..2973e34 --- /dev/null +++ b/groupTasks/groups/shx-new-product-steps/index.json @@ -0,0 +1,87 @@ +{ + "category": "Shinnex", + "name": "Schritte für neue Produktveröffentlichung", + "globalInputs": [], + "tasks": [ + { + "name": "Produktvideos/fotos erstellen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Produktvideos/fotos auf Seafile hochladen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Befehl auf Seafile ausführen um Bilder zu konvertieren", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "TikTok Video drehen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "TikTok Video schneiden", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Produktvideos schneiden", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Produkt in Shop online stellen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Produktpipeline aktualisieren", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "TikTok Video hochladen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + }, + { + "name": "Instagram Post hochladen", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "empty.py", + "parameters": [] + } + ] +} diff --git a/groupTasks/groups/shx-order-voucher-codes/index.json b/groupTasks/groups/shx-order-voucher-codes/index.json index 26c8e79..9cd49a4 100644 --- a/groupTasks/groups/shx-order-voucher-codes/index.json +++ b/groupTasks/groups/shx-order-voucher-codes/index.json @@ -4,7 +4,7 @@ "globalInputs": [], "tasks": [ { - "name": "Gutscheincodes für Bestellung erstellen (nur die Bestellnummer ohne #)", + "name": "Gutscheincodes für Bestellung erstellen", "onFinish": "next", "undoPossible": false, "repeatPossible": true, @@ -29,11 +29,6 @@ "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)" } ] } diff --git a/groupTasks/groups/shx-order-voucher-codes/script.py b/groupTasks/groups/shx-order-voucher-codes/script.py index b606015..adf505e 100644 --- a/groupTasks/groups/shx-order-voucher-codes/script.py +++ b/groupTasks/groups/shx-order-voucher-codes/script.py @@ -1,10 +1,11 @@ import requests import sys import json -import qrcode import subprocess import sys import os +import string +import random sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) @@ -26,24 +27,27 @@ headers = { json_object = json.loads(sys.argv[1]) customerEmail = json_object["customerEmail"] customerName = json_object["customerName"] -discountCode = json_object["discountCode"] productUrl = json_object["productUrl"] orderId = json_object["orderId"] if (customerEmail is None or orderId is None or customerName is None - or productUrl is None - or discountCode is None): + or productUrl is None): print("Missing required parameters") sys.exit(1) customerEmail = customerEmail["value"] customerName = customerName["value"] -discountCode = discountCode["value"] productUrl = productUrl["value"] orderId = orderId["value"] +# remove the # from the orderId if provided +if orderId.startswith('#'): + orderId = orderId[1:] + +discountCode = None + def CreateCrmCustomer(): response = requests.post( @@ -114,6 +118,49 @@ def CheckIfCrmCustomerExists(): GetCustomerActivityLinks(customerId=customerId) +# create shopify discount code +# this function will retry 3 times to create a new discount code if the random generate code already exists +def createShopifyDiscountCode(retries): + # generate random code + characters = string.ascii_uppercase + string.digits + discount_code = ''.join(random.choice(characters) for _ in range(12)) + + # load data from secrets + secrets = utils.get_secrets() + + shopify_url = secrets['shopify_url'] + x_shopify_access_token = secrets['x_shopify_access_token'] + shopify_discount_code_price_rule = secrets['shopify_discount_code_price_rule'] + + response = requests.post( + url=f"{shopify_url}/admin/api/2024-01/price_rules/{shopify_discount_code_price_rule}/discount_codes.json", + headers={ + "X-Shopify-Access-Token": x_shopify_access_token, + "Content-Type": "application/json" + }, + json={ + "discount_code": {"code": discount_code} + }) + + retries += 1 + + if retries >= 3: + sys.exit("Error, tried 3 times to create discount code") + + if response.status_code == 422: + print("Failed to create code, response status code 422. Trying to generate new discount code") + createShopifyDiscountCode(retries) + + if response.status_code != 201: + sys.exit(f"Failed to create discount code, status code: {response.status_code}") + + print(f"Created discount code: {discount_code}") + + global discountCode + + discountCode = discount_code + + def CreateCrmActivityLink(customerId, thirdVoucher): print(f"Creating CRM activity link for customer {customerId}") @@ -133,6 +180,8 @@ def CreateCrmActivityLink(customerId, thirdVoucher): print(f"CreateCrmActivityLink req error {response.status_code}") sys.exit(1) + createShopifyDiscountCode(0) + req("10 % Gutschein", f"https://shinnex.de/discount/{discountCode}?utm_source=order&utm_medium=qrcode&utm_campaign=ordervouchercodes&utm_content=reedemvouchercode") req("5 € Gutschein", f"{productUrl}?utm_source=order&utm_medium=qrcode&utm_campaign=ordervouchercodes&utm_content=qualifyforvouchercode") diff --git a/groupTasks/groups/shx-product-label/index.json b/groupTasks/groups/shx-product-label/index.json index fe67c1b..73c0c65 100644 --- a/groupTasks/groups/shx-product-label/index.json +++ b/groupTasks/groups/shx-product-label/index.json @@ -26,8 +26,11 @@ "#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)", + "#58324 Ruby die Schlange, FARBE, Lila/Blau, (Glänzend)", "#78648 Ruby die Schlange, FARBE, Gold, (Glänzend)", + "#15809 Ruby die Schlange, FARBE, Himmelblau, (Fluoreszierend)", + "#49461 Ruby die Schlange, FARBE, Rosa, (Matt)", + "#84491 Ruby die Schlange, FARBE, Rot/Schwarz, (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)", @@ -53,8 +56,13 @@ "#35717 Stella der Phönix, FARBE, Sonderanfertigung, Rosa/Weiß", "#26843 Stella der Phönix, FARBE, Verlauf Lila/Pink, ", "#74943 Brain der Fuchs, STIL, Standard, ", - "#78071 Weißer Hund, STIL, Weiß, ", - "#92734 Amigo der Capybara, FARBE, Braun, " + "#78071 Lucky der Barsoi, FARBE, Weiß, ", + "#92734 Amigo der Capybara, FARBE, Braun, ", + "#22318 Witty der Fuchs, STIL, Standard, ", + "#23732 Witty der Fuchs, STIL, Standard, Mit Halstuch", + "#72175 Paco die Bulldogge, FARBE, Grau, ", + "#55172 Sharky der Hai, FARBE, Grau, ", + "#10971 Chibi die Ratte, FARBE, Grau, " ], "global": false } diff --git a/groupTasks/groupsData/google-sheet-filaments.json b/groupTasks/groupsData/google-sheet-filaments.json index 4b67f29..76debf1 100644 --- a/groupTasks/groupsData/google-sheet-filaments.json +++ b/groupTasks/groupsData/google-sheet-filaments.json @@ -107,6 +107,12 @@ "name_color": "Gelb", "material": "Matte PLA", "manufacturer": "OVERTURE" + }, + { + "id": "29", + "name_color": "Rot/Schwarz", + "material": "Dual-Color Silk PLA", + "manufacturer": "AMOLEN" } ] } \ No newline at end of file diff --git a/groupTasks/groupsData/google-sheet-products.json b/groupTasks/groupsData/google-sheet-products.json index 5dd8c2f..36130bb 100644 --- a/groupTasks/groupsData/google-sheet-products.json +++ b/groupTasks/groupsData/google-sheet-products.json @@ -46,7 +46,7 @@ "id": "58324", "name": "Ruby_die Schlange", "product_variant": "FARBE", - "product_characteristic_line_1": "Rot/Blau", + "product_characteristic_line_1": "Lila/Blau", "product_characteristic_line_2": "(Glänzend)" }, { @@ -56,6 +56,27 @@ "product_characteristic_line_1": "Gold", "product_characteristic_line_2": "(Glänzend)" }, + { + "id": "15809", + "name": "Ruby_die Schlange", + "product_variant": "FARBE", + "product_characteristic_line_1": "Himmelblau", + "product_characteristic_line_2": "(Fluoreszierend)" + }, + { + "id": "49461", + "name": "Ruby_die Schlange", + "product_variant": "FARBE", + "product_characteristic_line_1": "Rosa", + "product_characteristic_line_2": "(Matt)" + }, + { + "id": "84491", + "name": "Ruby_die Schlange", + "product_variant": "FARBE", + "product_characteristic_line_1": "Rot/Schwarz", + "product_characteristic_line_2": "(Glänzend)" + }, { "id": "21433", "name": "Bruno_der Dino", @@ -233,8 +254,8 @@ }, { "id": "78071", - "name": "Weißer_Hund", - "product_variant": "STIL", + "name": "Lucky_der Barsoi", + "product_variant": "FARBE", "product_characteristic_line_1": "Weiß", "product_characteristic_line_2": "" }, @@ -244,6 +265,41 @@ "product_variant": "FARBE", "product_characteristic_line_1": "Braun", "product_characteristic_line_2": "" + }, + { + "id": "22318", + "name": "Witty_der Fuchs", + "product_variant": "STIL", + "product_characteristic_line_1": "Standard", + "product_characteristic_line_2": "" + }, + { + "id": "23732", + "name": "Witty_der Fuchs", + "product_variant": "STIL", + "product_characteristic_line_1": "Standard", + "product_characteristic_line_2": "Mit Halstuch" + }, + { + "id": "72175", + "name": "Paco_die Bulldogge", + "product_variant": "FARBE", + "product_characteristic_line_1": "Grau", + "product_characteristic_line_2": "" + }, + { + "id": "55172", + "name": "Sharky_der Hai", + "product_variant": "FARBE", + "product_characteristic_line_1": "Grau", + "product_characteristic_line_2": "" + }, + { + "id": "10971", + "name": "Chibi_die Ratte", + "product_variant": "FARBE", + "product_characteristic_line_1": "Grau", + "product_characteristic_line_2": "" } ] } \ 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 fb84667d67d619b86eff7a62414eb8f8510fdf01..c2bcdfc822976bd06cf543989f701193e40c0761 100644 GIT binary patch delta 864 zcmZvaO-NKx6vyv*zBlvceL3UPoE**ZqshmRsi;s;fi0?ygf66skYUc#EOqR@N01b= zuxJ$_*KJfFvv%0)L=e$Bf;wl?Sw#1~`}?1J@3~*+yf1z4`n{^_T7pWg zD_%OA+xB{4XS+Pv5D2TON(wb>dmt)l)X^X{F@Q@OYJ5ZT>C$e&VQYwRQB7vXVQ6nDlZMoB9xbWJ zS}5h%9AN~EUdAzoM@WoXedF$g%&H&O+|mDSJxE^H)iwJB461@Npmyzon?O-=pnk#- z9rD4Raqmzs;&=&=Q{*?7pCG&G6lk(}1r9|374^^=@TbY%q!v+lX^91LTD@^@LrIn0 zr+%WZRd0nAi@CV6R$UGg_1P`LY4yt;gN8ck^*1fL41>Wb`J1aV sY@KJgj7~;@QDh7^6UbSYoF6&G;73c2i=0uC_7T;D&E!J5Td+}ng z9_m9pd8*(|ko8aKrT7O3;$6X$^j1WDZ-qUXfzRj7Uo+i#t_Y2wJ9QC84Go9$o)9kxP+F55*9eYS@IhHM`rjM)JuILZ!j3{!T5r*NDd zBdi(4#D~KMfJ@)uJ(Tp?yq1n}9_qBM(Ln(BV8H31!Z~=n7U5CV5Z-2-T@@^NnLNn94XAw-PpX}UEk?Ex~HYP z_J;_h${APavbzX*|B35Br6H^H^xV7EOr&fI76em*X+gv&?K=;4cH26B>91D*w{ym! z+qC5`Kt`<~r;q+rcmkOQUO#~b_xS2x3Lo>VXEF@XZO*Mup5b~BDoj22f<;~^;0wJ9 z^1-d_^1Np;4DdiN(NXXa=ILViCM~V)&Q`bdgzKBzox9zVeuNpEryx2D&uAr@TU(ah z5?!$LX@M<}6a72t1*t+oDyRu&1$BX3m(B!jf&3)BOi$xxT`~%WV??>iQ8neUCsb8g G%Ki%{$aehz diff --git a/groupTasks/libs/utils/utils.py b/groupTasks/libs/utils/utils.py index 9158e9a..014b3cc 100644 --- a/groupTasks/libs/utils/utils.py +++ b/groupTasks/libs/utils/utils.py @@ -4,6 +4,7 @@ import os import shutil import sys import qrcode +import json def clear_workspace(files): @@ -142,3 +143,8 @@ def create_qrcode(qr_code_url, save_path, back_color): # Save image to a file # like ./test.png img.save(save_path) + + +def get_secrets(): + with open('../../secrets/secrets.json') as content: + return json.load(content) \ No newline at end of file