use of secrets
parent
64e68855f1
commit
4868faba72
|
@ -1,17 +1,17 @@
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
try:
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||||
with open('../../secrets/admin-dashboard-api-key.txt') as f:
|
|
||||||
adminDashboardApiKey = f.read().strip() # `.strip()` to remove any extra whitespace or newlines
|
from libs.utils import utils
|
||||||
except FileNotFoundError:
|
|
||||||
sys.exit("Error: API key file not found.")
|
# load data from secrets
|
||||||
except Exception as e:
|
secrets = utils.get_secrets()
|
||||||
sys.exit(f"Error reading the API key file: {e}")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.get("https://devdash.ex.umbach.dev/api/v1/productpipeline/update",
|
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
|
res.raise_for_status() # Raises a HTTPError if the HTTP request returned an unsuccessful status code
|
||||||
except requests.exceptions.HTTPError as http_err:
|
except requests.exceptions.HTTPError as http_err:
|
||||||
sys.exit(f"HTTP error occurred: {http_err}") # HTTP error
|
sys.exit(f"HTTP error occurred: {http_err}") # HTTP error
|
||||||
|
|
|
@ -7,20 +7,17 @@ import os
|
||||||
import string
|
import string
|
||||||
import random
|
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
|
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
|
# MAIN
|
||||||
|
|
||||||
|
# load data from secrets
|
||||||
|
secrets = utils.get_secrets()
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"X-Api-Key": API_KEY,
|
"X-Api-Key": secrets["admin_dashboard"]["x_api_key"],
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +40,7 @@ productUrl = productUrl["value"]
|
||||||
orderId = orderId["value"]
|
orderId = orderId["value"]
|
||||||
|
|
||||||
# remove the # from the orderId if provided
|
# remove the # from the orderId if provided
|
||||||
if orderId.startswith('#'):
|
if orderId.startswith("#"):
|
||||||
orderId = orderId[1:]
|
orderId = orderId[1:]
|
||||||
|
|
||||||
discountCode = None
|
discountCode = None
|
||||||
|
@ -51,7 +48,7 @@ discountCode = None
|
||||||
|
|
||||||
def CreateCrmCustomer():
|
def CreateCrmCustomer():
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{ENDPOINT_URL}/customer/create",
|
url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/customer/create",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json={
|
json={
|
||||||
"FirstName": customerName,
|
"FirstName": customerName,
|
||||||
|
@ -86,7 +83,7 @@ def CheckIfCrmCustomerExists():
|
||||||
print(f"Checking if customer exists: {customerEmail}")
|
print(f"Checking if customer exists: {customerEmail}")
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{ENDPOINT_URL}/customer",
|
url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/customer",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json={"Email": customerEmail} # Hier json verwenden, um JSON-Daten zu senden
|
json={"Email": customerEmail} # Hier json verwenden, um JSON-Daten zu senden
|
||||||
)
|
)
|
||||||
|
@ -123,19 +120,19 @@ def CheckIfCrmCustomerExists():
|
||||||
def createShopifyDiscountCode(retries):
|
def createShopifyDiscountCode(retries):
|
||||||
# generate random code
|
# generate random code
|
||||||
characters = string.ascii_uppercase + string.digits
|
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
|
# load data from secrets
|
||||||
secrets = utils.get_secrets()
|
shopify_secrets = secrets["shopify"]
|
||||||
|
|
||||||
shopify_url = secrets['shopify_url']
|
shopify_url = shopify_secrets["store_url"]
|
||||||
x_shopify_access_token = secrets['x_shopify_access_token']
|
x_shopify_app_access_token = shopify_secrets["x_shopify_app_access_token"]
|
||||||
shopify_discount_code_price_rule = secrets['shopify_discount_code_price_rule']
|
shopify_discount_code_price_rule = shopify_secrets["discount_price_rules"]["order_voucher_10_percent"]
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{shopify_url}/admin/api/2024-01/price_rules/{shopify_discount_code_price_rule}/discount_codes.json",
|
url=f"{shopify_url}/admin/api/2024-01/price_rules/{shopify_discount_code_price_rule}/discount_codes.json",
|
||||||
headers={
|
headers={
|
||||||
"X-Shopify-Access-Token": x_shopify_access_token,
|
"X-Shopify-Access-Token": x_shopify_app_access_token,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
json={
|
json={
|
||||||
|
@ -166,7 +163,7 @@ def CreateCrmActivityLink(customerId, thirdVoucher):
|
||||||
|
|
||||||
def req(type, url):
|
def req(type, url):
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{ENDPOINT_URL}/links",
|
url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/links",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json={
|
json={
|
||||||
"CustomerId": customerId,
|
"CustomerId": customerId,
|
||||||
|
@ -182,7 +179,7 @@ def CreateCrmActivityLink(customerId, thirdVoucher):
|
||||||
|
|
||||||
createShopifyDiscountCode(0)
|
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")
|
req("5 € Gutschein", f"{productUrl}?utm_source=order&utm_medium=qrcode&utm_campaign=ordervouchercodes&utm_content=qualifyforvouchercode")
|
||||||
|
|
||||||
if thirdVoucher:
|
if thirdVoucher:
|
||||||
|
@ -191,7 +188,7 @@ def CreateCrmActivityLink(customerId, thirdVoucher):
|
||||||
|
|
||||||
def GetCustomerActivityLinks(customerId, thirdVoucher):
|
def GetCustomerActivityLinks(customerId, thirdVoucher):
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
url=f"{ENDPOINT_URL}/customer/view/{customerId}",
|
url=f"{secrets['admin_dashboard']['crm_endpoint_url']}/customer/view/{customerId}",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -229,11 +226,13 @@ def GetCustomerActivityLinks(customerId, thirdVoucher):
|
||||||
print("Gift links not found")
|
print("Gift links not found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
utils.create_qrcode(f"{QR_CODE_URL}{linkGift5['Id']}", "./5euro.png", "#fdf8ef")
|
qr_code_url = secrets["admin_dashboard"]["qr_code_url"]
|
||||||
utils.create_qrcode(f"{QR_CODE_URL}{linkGift10Percent['Id']}", "./10percent.png", "#fdf8ef")
|
|
||||||
|
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:
|
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():
|
def ReplaceHtmlVariables():
|
||||||
|
@ -242,7 +241,7 @@ def ReplaceHtmlVariables():
|
||||||
# replace variables in html file
|
# replace variables in html file
|
||||||
# read html file and replace variables
|
# 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)
|
data = json.load(json_file)
|
||||||
|
|
||||||
randomTextIndex = random.randint(0, len(data["texts"])-1)
|
randomTextIndex = random.randint(0, len(data["texts"])-1)
|
||||||
|
@ -314,7 +313,7 @@ if __name__ == "__main__":
|
||||||
createPdf("frontPage.html", "finalFrontPage.pdf")
|
createPdf("frontPage.html", "finalFrontPage.pdf")
|
||||||
createPdf("backPage.html", "finalBackPage.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",
|
utils.clear_workspace(["5euro.png", "10euro.png", "10percent.png",
|
||||||
"frontPage.html", "backPage.html", "finalBackPage.pdf",
|
"frontPage.html", "backPage.html", "finalBackPage.pdf",
|
||||||
|
|
Loading…
Reference in New Issue