diff --git a/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py b/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py index 3ab7972..0d9fce4 100644 --- a/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py +++ b/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py @@ -1,17 +1,17 @@ import sys +import os import requests -try: - with open('../../secrets/admin-dashboard-api-key.txt') as f: - adminDashboardApiKey = f.read().strip() # `.strip()` to remove any extra whitespace or newlines -except FileNotFoundError: - sys.exit("Error: API key file not found.") -except Exception as e: - sys.exit(f"Error reading the API key file: {e}") +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) + +from libs.utils import utils + +# load data from secrets +secrets = utils.get_secrets() try: res = requests.get("https://devdash.ex.umbach.dev/api/v1/productpipeline/update", - headers={"X-Api-key": adminDashboardApiKey}) + headers={"X-Api-key": secrets["admin_dashboard"]["x_api_key"]}) res.raise_for_status() # Raises a HTTPError if the HTTP request returned an unsuccessful status code except requests.exceptions.HTTPError as http_err: sys.exit(f"HTTP error occurred: {http_err}") # HTTP error diff --git a/groupTasks/groups/shx-order-voucher-codes/script.py b/groupTasks/groups/shx-order-voucher-codes/script.py index f4a0156..6828b15 100644 --- a/groupTasks/groups/shx-order-voucher-codes/script.py +++ b/groupTasks/groups/shx-order-voucher-codes/script.py @@ -7,20 +7,17 @@ import os import string import random -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))) from libs.utils import utils -# DEFINITIONS - -ENDPOINT_URL = "https://devdash.ex.umbach.dev/api/v1/crm" -API_KEY = "uY1DTUog-Iax7-ydc4-dP9V-NON1xsbTGH1I" -QR_CODE_URL = "https://link.shinnex.de/" - # MAIN +# load data from secrets +secrets = utils.get_secrets() + headers = { - "X-Api-Key": API_KEY, + "X-Api-Key": secrets["admin_dashboard"]["x_api_key"], "Content-Type": "application/json" } @@ -43,7 +40,7 @@ productUrl = productUrl["value"] orderId = orderId["value"] # remove the # from the orderId if provided -if orderId.startswith('#'): +if orderId.startswith("#"): orderId = orderId[1:] discountCode = None @@ -51,7 +48,7 @@ discountCode = None def CreateCrmCustomer(): response = requests.post( - url=f"{ENDPOINT_URL}/customer/create", + url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/customer/create", headers=headers, json={ "FirstName": customerName, @@ -86,7 +83,7 @@ def CheckIfCrmCustomerExists(): print(f"Checking if customer exists: {customerEmail}") response = requests.post( - url=f"{ENDPOINT_URL}/customer", + url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/customer", headers=headers, json={"Email": customerEmail} # Hier json verwenden, um JSON-Daten zu senden ) @@ -123,19 +120,19 @@ def CheckIfCrmCustomerExists(): def createShopifyDiscountCode(retries): # generate random code characters = string.ascii_uppercase + string.digits - discount_code = ''.join(random.choice(characters) for _ in range(12)) + discount_code = "".join(random.choice(characters) for _ in range(12)) # load data from secrets - secrets = utils.get_secrets() + shopify_secrets = secrets["shopify"] - 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'] + shopify_url = shopify_secrets["store_url"] + x_shopify_app_access_token = shopify_secrets["x_shopify_app_access_token"] + shopify_discount_code_price_rule = shopify_secrets["discount_price_rules"]["order_voucher_10_percent"] 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, + "X-Shopify-Access-Token": x_shopify_app_access_token, "Content-Type": "application/json" }, json={ @@ -166,7 +163,7 @@ def CreateCrmActivityLink(customerId, thirdVoucher): def req(type, url): response = requests.post( - url=f"{ENDPOINT_URL}/links", + url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/links", headers=headers, json={ "CustomerId": customerId, @@ -182,7 +179,7 @@ def CreateCrmActivityLink(customerId, thirdVoucher): createShopifyDiscountCode(0) - req("10 % Gutschein", f"https://shinnex.de/discount/{discountCode}?utm_source=order&utm_medium=qrcode&utm_campaign=ordervouchercodes&utm_content=reedemvouchercode") + req("10 % Gutschein", f"{secrets['shopify']['public_url']}/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") if thirdVoucher: @@ -191,7 +188,7 @@ def CreateCrmActivityLink(customerId, thirdVoucher): def GetCustomerActivityLinks(customerId, thirdVoucher): response = requests.get( - url=f"{ENDPOINT_URL}/customer/view/{customerId}", + url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/customer/view/{customerId}", headers=headers, ) @@ -229,11 +226,13 @@ def GetCustomerActivityLinks(customerId, thirdVoucher): print("Gift links not found") sys.exit(1) - utils.create_qrcode(f"{QR_CODE_URL}{linkGift5['Id']}", "./5euro.png", "#fdf8ef") - utils.create_qrcode(f"{QR_CODE_URL}{linkGift10Percent['Id']}", "./10percent.png", "#fdf8ef") + qr_code_url = secrets["admin_dashboard"]["qr_code_url"] + + utils.create_qrcode(f"{qr_code_url}{linkGift5['Id']}", "./5euro.png", "#fdf8ef") + utils.create_qrcode(f"{qr_code_url}{linkGift10Percent['Id']}", "./10percent.png", "#fdf8ef") if thirdVoucher: - utils.create_qrcode(f"{QR_CODE_URL}{linkGift10['Id']}", "./10euro.png", "#fdf8ef") + utils.create_qrcode(f"{qr_code_url}{linkGift10['Id']}", "./10euro.png", "#fdf8ef") def ReplaceHtmlVariables(): @@ -242,7 +241,7 @@ def ReplaceHtmlVariables(): # replace variables in html file # read html file and replace variables - with open("../../groupsData/shx-order-voucher-codes/texte.json", 'r', encoding='utf-8') as json_file: + with open("../../groupsData/shx-order-voucher-codes/texte.json", "r", encoding="utf-8") as json_file: data = json.load(json_file) randomTextIndex = random.randint(0, len(data["texts"])-1) @@ -314,7 +313,7 @@ if __name__ == "__main__": createPdf("frontPage.html", "finalFrontPage.pdf") createPdf("backPage.html", "finalBackPage.pdf") - utils.merge_pdfs('finalFrontPage.pdf', 'finalBackPage.pdf', 'Gutscheine.pdf') + utils.merge_pdfs("finalFrontPage.pdf", "finalBackPage.pdf", "Gutscheine.pdf") utils.clear_workspace(["5euro.png", "10euro.png", "10percent.png", "frontPage.html", "backPage.html", "finalBackPage.pdf",