From 049084f705c5b4e3d6e67de3f0b0b93447ee4750 Mon Sep 17 00:00:00 2001
From: alex
Date: Wed, 24 Jul 2024 17:43:48 +0200
Subject: [PATCH] auto create shopify discount code and moved to secrets
---
.../index.json | 5 ---
.../script.py | 39 +++++++++---------
.../email.html | 4 +-
.../email.txt | 7 ++--
.../utils/__pycache__/utils.cpython-39.pyc | Bin 5456 -> 5408 bytes
5 files changed, 25 insertions(+), 30 deletions(-)
diff --git a/groupTasks/groups/shx-order-voucher-code-activated/index.json b/groupTasks/groups/shx-order-voucher-code-activated/index.json
index 67158e6..3ca4949 100644
--- a/groupTasks/groups/shx-order-voucher-code-activated/index.json
+++ b/groupTasks/groups/shx-order-voucher-code-activated/index.json
@@ -15,11 +15,6 @@
"type": "text",
"displayName": "E-Mail vom Kunden"
},
- {
- "parameterName": "voucher_code",
- "type": "text",
- "displayName": "Gutscheincode für den Kunden (in Shopify erstellen)"
- },
{
"parameterName": "voucher_type",
"type": "select",
diff --git a/groupTasks/groups/shx-order-voucher-code-activated/script.py b/groupTasks/groups/shx-order-voucher-code-activated/script.py
index 42235a7..5ad4eed 100644
--- a/groupTasks/groups/shx-order-voucher-code-activated/script.py
+++ b/groupTasks/groups/shx-order-voucher-code-activated/script.py
@@ -16,35 +16,26 @@ STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/"
json_object = json.loads(sys.argv[1])
customer_email = json_object["customer_email"]
-voucher_code = json_object["voucher_code"]
voucher_type = json_object["voucher_type"]
-if (customer_email is None
- or voucher_code is None
- or voucher_type is None):
+if customer_email is None or voucher_type is None:
print("Missing required parameters")
sys.exit(1)
customer_email = customer_email["value"]
-voucher_code = voucher_code["value"]
voucher_type = voucher_type["value"]
-def load_email_config(filename):
- with open(filename, "r") as f:
- config = yaml.safe_load(f)
- return config["email"], config["smtp"]
-
-email_config, smtp_config = load_email_config(f"{STATIC_PATH}config.yml")
+secrets = utils.get_secrets()["email"]
# extract the email parameters
-auth_email = email_config["auth_email"]
-from_email_name = email_config["from_email_name"]
-from_email = email_config["from_email"]
-password = email_config["password"]
+auth_email = secrets["auth_email"]
+from_email_name = secrets["from_email_name"]
+from_email = secrets["from_email"]
+password = secrets["password"]
# extract the smtp parameters
-smtp_server = smtp_config["server"]
-smtp_port = smtp_config["port"]
+smtp_server = secrets["smtp_server"]
+smtp_port = secrets["smtp_port"]
receiver_email = customer_email
@@ -66,16 +57,24 @@ with open(f"{STATIC_PATH}email.html", "r") as file:
if voucher_type == "5 €":
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, uns zu bewerten. Deine Meinung ist uns sehr wichtig und hilft uns, unseren Service stetig zu verbessern."
price = "5"
+
+ discount_code = utils.create_shopify_discount_code("order_voucher_5_euro")
else:
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, einen Beitrag über uns auf Social Media zu erstellen."
price = "10"
+ discount_code = utils.create_shopify_discount_code("order_voucher_10_euro")
+
+if discount_code == "":
+ sys.exit("Discount code is empty")
+
html = html.replace("{{PRICE}}", price)
html = html.replace("{{MESSAGE}}", message)
-html = html.replace("{{VOUCHER_CODE}}", voucher_code)
+html = html.replace("{{DISCOUNT_CODE}}", discount_code)
+text = text.replace("{{PRICE}}", price)
text = text.replace("{{MESSAGE}}", message)
-text = text.replace("{{VOUCHER_CODE}}", voucher_code)
+text = text.replace("{{DISCOUNT_CODE}}", discount_code)
# add text and html part to the email
part1 = MIMEText(text, "plain", "utf-8")
@@ -91,7 +90,7 @@ try:
server.login(auth_email, password)
server.sendmail(from_email, receiver_email, msg.as_string())
- print(f"Email sent to {receiver_email} with voucher code {voucher_code} of type {voucher_type}")
+ print(f"Email sent to {receiver_email} with voucher code {discount_code} of type {voucher_type}")
except Exception as e:
print(f"Error sending email: {e}")
sys.exit(1)
\ No newline at end of file
diff --git a/groupTasks/groupsData/shx-order-voucher-code-activated/email.html b/groupTasks/groupsData/shx-order-voucher-code-activated/email.html
index 448a664..0d7b5f0 100644
--- a/groupTasks/groupsData/shx-order-voucher-code-activated/email.html
+++ b/groupTasks/groupsData/shx-order-voucher-code-activated/email.html
@@ -151,7 +151,7 @@
"
>
Dein Gutscheincode lautet:
- {{VOUCHER_CODE}}
+ {{DISCOUNT_CODE}}