code structure
parent
3f11e1db83
commit
b436985bc9
|
@ -69,7 +69,7 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code-box first-item">
|
<div class="code-box first-item">
|
||||||
<span>SYfwa2g</span>
|
<span>{{DISCOUNT_CODE}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container-action">
|
<div class="container-action">
|
||||||
<img class="image-11-icon" alt="" src="./qrcode.png" />
|
<img class="image-11-icon" alt="" src="./5euro.png" />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="status-box">
|
<div class="status-box">
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container-action">
|
<div class="container-action">
|
||||||
<img class="image-11-icon" alt="" src="./qrcode.png" />
|
<img class="image-11-icon" alt="" src="./10euro.png" />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="status-box">
|
<div class="status-box">
|
||||||
|
|
|
@ -1,34 +1,43 @@
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import qrcode
|
||||||
|
|
||||||
# DEFINITIONS
|
# DEFINITIONS
|
||||||
|
|
||||||
endpoint_url = "https://devdash.ex.umbach.dev/api/v1/crm"
|
ENDPOINT_URL = "https://devdash.ex.umbach.dev/api/v1/crm"
|
||||||
api_key = "uY1DTUog-Iax7-ydc4-dP9V-NON1xsbTGH1I"
|
API_KEY = "uY1DTUog-Iax7-ydc4-dP9V-NON1xsbTGH1I"
|
||||||
|
QR_CODE_URL = "https://devdash.ex.umbach.dev/api/v1/crm/link/"
|
||||||
headers = {
|
|
||||||
"X-Api-Key": api_key,
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
# MAIN
|
# MAIN
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"X-Api-Key": API_KEY,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
json_object = json.loads(sys.argv[1])
|
json_object = json.loads(sys.argv[1])
|
||||||
customerEmail = json_object["customerEmail"]
|
customerEmail = json_object["customerEmail"]
|
||||||
|
customerName = json_object["customerName"]
|
||||||
|
discountCode = json_object["discountCode"]
|
||||||
orderId = json_object["orderId"]
|
orderId = json_object["orderId"]
|
||||||
|
|
||||||
if customerEmail is None:
|
if (customerEmail is None
|
||||||
print("customerEmail is required")
|
or orderId is None
|
||||||
|
or customerName is None
|
||||||
|
or discountCode is None):
|
||||||
|
print("Missing required parameters")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
customerEmail = customerEmail["value"]
|
customerEmail = customerEmail["value"]
|
||||||
|
customerName = customerName["value"]
|
||||||
|
discountCode = discountCode["value"]
|
||||||
orderId = orderId["value"]
|
orderId = orderId["value"]
|
||||||
|
|
||||||
|
|
||||||
def CreateCrmCustomer():
|
def CreateCrmCustomer():
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{endpoint_url}/customer/create",
|
url=f"{ENDPOINT_URL}/customer/create",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json={
|
json={
|
||||||
"FirstName": "Shopify Customer",
|
"FirstName": "Shopify Customer",
|
||||||
|
@ -36,13 +45,12 @@ def CreateCrmCustomer():
|
||||||
"LeadOrigin": "Shopify Customer added by GroupTask",
|
"LeadOrigin": "Shopify Customer added by GroupTask",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
print(f"CreateCrmCustomer response status code {response.status_code}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print(f"CreateCrmCustomer req error {response.status_code}")
|
print(f"CreateCrmCustomer req error {response.status_code}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print(response.status_code)
|
|
||||||
print(response.json())
|
|
||||||
|
|
||||||
return response.json()["Id"]
|
return response.json()["Id"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +58,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"{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
|
||||||
)
|
)
|
||||||
|
@ -74,6 +82,7 @@ def CheckIfCrmCustomerExists():
|
||||||
customerId = response.json()[0]["Id"]
|
customerId = response.json()[0]["Id"]
|
||||||
|
|
||||||
CreateCrmActivityLink(customerId=customerId)
|
CreateCrmActivityLink(customerId=customerId)
|
||||||
|
GetCustomerActivityLinks(customerId=customerId)
|
||||||
|
|
||||||
|
|
||||||
def CreateCrmActivityLink(customerId):
|
def CreateCrmActivityLink(customerId):
|
||||||
|
@ -81,7 +90,7 @@ def CreateCrmActivityLink(customerId):
|
||||||
|
|
||||||
def req(type):
|
def req(type):
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=f"{endpoint_url}/links",
|
url=f"{ENDPOINT_URL}/links",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json={
|
json={
|
||||||
"CustomerId": customerId,
|
"CustomerId": customerId,
|
||||||
|
@ -89,15 +98,111 @@ def CreateCrmActivityLink(customerId):
|
||||||
"Url": "https://www.example.com"
|
"Url": "https://www.example.com"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
print(f"CreateCrmActivityLink response status code {response.status_code} for {type}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print(f"CreateCrmActivityLink req error {response.status_code}")
|
print(f"CreateCrmActivityLink req error {response.status_code}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print(response.status_code)
|
|
||||||
|
|
||||||
req("5 € Gutschein")
|
req("5 € Gutschein")
|
||||||
req("10 € Gutschein")
|
req("10 € Gutschein")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_qrcode(type, id):
|
||||||
|
data = f"{QR_CODE_URL}{id}"
|
||||||
|
|
||||||
|
# Generate QR code
|
||||||
|
qr = qrcode.QRCode(
|
||||||
|
version=1,
|
||||||
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||||
|
box_size=10,
|
||||||
|
border=0,
|
||||||
|
)
|
||||||
|
qr.add_data(data)
|
||||||
|
qr.make(fit=True)
|
||||||
|
|
||||||
|
# Create an image from the QR Code instance
|
||||||
|
img = qr.make_image(fill_color="black", back_color="#fdf8ef")
|
||||||
|
|
||||||
|
# Save image to a file
|
||||||
|
img.save(f"./{type}.png")
|
||||||
|
|
||||||
|
# Display the generated QR code image
|
||||||
|
img.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def GetCustomerActivityLinks(customerId):
|
||||||
|
response = requests.get(
|
||||||
|
url=f"{ENDPOINT_URL}/customer/view/{customerId}",
|
||||||
|
headers=headers,
|
||||||
|
json={
|
||||||
|
"CustomerId": customerId,
|
||||||
|
"Name": f"Shopify Order #{orderId} - {type}",
|
||||||
|
"Url": "https://www.example.com"
|
||||||
|
})
|
||||||
|
|
||||||
|
print(f"GetCustomerActivityLinks response status code {response.status_code}")
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
print(f"GetCustomerActivityLinks req error {response.status_code}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
data = response.json()["Links"]
|
||||||
|
|
||||||
|
if len(data) == 0:
|
||||||
|
print("No links found")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# sort data by creation date
|
||||||
|
|
||||||
|
data = sorted(data, key=lambda x: x["CreatedAt"], reverse=True)
|
||||||
|
|
||||||
|
# find the first link that has a name that starts with "Shopify Order #orderId - price € Gutschein"
|
||||||
|
|
||||||
|
linkGift5 = None
|
||||||
|
linkGift10 = None
|
||||||
|
|
||||||
|
for link in data:
|
||||||
|
if linkGift5 is None and link["Name"].startswith(f"Shopify Order #{orderId} - 5 € Gutschein"):
|
||||||
|
linkGift5 = link
|
||||||
|
elif linkGift10 is None and link["Name"].startswith(f"Shopify Order #{orderId} - 10 € Gutschein"):
|
||||||
|
linkGift10 = link
|
||||||
|
|
||||||
|
if linkGift5 is None or linkGift10 is None:
|
||||||
|
print("Gift links not found")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
create_qrcode("5euro", linkGift5["Id"])
|
||||||
|
create_qrcode("10euro", linkGift10["Id"])
|
||||||
|
|
||||||
|
|
||||||
|
def ReplaceHtmlVariables():
|
||||||
|
print("ReplaceHtmlVariables")
|
||||||
|
|
||||||
|
# replace variables in html file
|
||||||
|
# read html file and replace variables
|
||||||
|
|
||||||
|
file = open("frontPage.html", "r")
|
||||||
|
html = file.read()
|
||||||
|
html = html.replace("{{CUSTOMER_NAME}}", customerName)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
file = open("frontPage.html", "w")
|
||||||
|
file.write(html)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
file = open("backPage.html", "r")
|
||||||
|
html = file.read()
|
||||||
|
html = html.replace("{{DISCOUNT_CODE}}", discountCode)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
file = open("backPage.html", "w")
|
||||||
|
file.write(html)
|
||||||
|
file.close()
|
||||||
|
|
||||||
CheckIfCrmCustomerExists()
|
CheckIfCrmCustomerExists()
|
||||||
|
|
||||||
|
ReplaceHtmlVariables()
|
||||||
|
|
|
@ -1,43 +1,8 @@
|
||||||
import os
|
|
||||||
import pdfkit
|
|
||||||
import qrcode
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import PyPDF2
|
import PyPDF2
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def createPdf(sourceHtml, outputPdf):
|
||||||
def create_pdf_from_html(html_file, pdf_file):
|
|
||||||
pdfkit.from_file(html_file, pdf_file, options={"page-size": "A5", "orientation": "Landscape", "enable-local-file-access": ""})
|
|
||||||
|
|
||||||
|
|
||||||
def list_files_in_directory(directory):
|
|
||||||
files = os.listdir(directory)
|
|
||||||
for file in files:
|
|
||||||
print(file)
|
|
||||||
|
|
||||||
|
|
||||||
def create_qrcode():
|
|
||||||
data = "https://www.example.com"
|
|
||||||
|
|
||||||
# Generate QR code
|
|
||||||
qr = qrcode.QRCode(
|
|
||||||
version=1,
|
|
||||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
||||||
box_size=10,
|
|
||||||
border=4,
|
|
||||||
)
|
|
||||||
qr.add_data(data)
|
|
||||||
qr.make(fit=True)
|
|
||||||
|
|
||||||
# Create an image from the QR Code instance
|
|
||||||
img = qr.make_image(fill_color="black", back_color="#fdf8ef")
|
|
||||||
|
|
||||||
# Save image to a file
|
|
||||||
img.save("./example_qr.png")
|
|
||||||
|
|
||||||
# Display the generated QR code image
|
|
||||||
img.show()
|
|
||||||
|
|
||||||
def test(sourceHtml, outputPdf):
|
|
||||||
command = [
|
command = [
|
||||||
"google-chrome-stable",
|
"google-chrome-stable",
|
||||||
"--headless",
|
"--headless",
|
||||||
|
@ -51,10 +16,15 @@ def test(sourceHtml, outputPdf):
|
||||||
]
|
]
|
||||||
|
|
||||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdout, stderr = process.communicate()
|
_, stderr = process.communicate()
|
||||||
|
|
||||||
|
if process.returncode != 0:
|
||||||
|
print("Error creating PDF")
|
||||||
|
print(stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("PDF created successfully")
|
||||||
|
|
||||||
print("STDOUT:", stdout)
|
|
||||||
print("STDERR:", stderr)
|
|
||||||
|
|
||||||
def merge_pdfs(pdf1_path, pdf2_path, output_path):
|
def merge_pdfs(pdf1_path, pdf2_path, output_path):
|
||||||
# Öffne die beiden PDF-Dateien
|
# Öffne die beiden PDF-Dateien
|
||||||
|
@ -81,14 +51,12 @@ def merge_pdfs(pdf1_path, pdf2_path, output_path):
|
||||||
pdf_writer.write(output_file)
|
pdf_writer.write(output_file)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
directory = "oldFiles/" # Aktuelles Verzeichnis
|
createPdf("oldFiles/frontPage.html", "finalFrontPage.pdf")
|
||||||
list_files_in_directory(directory)
|
createPdf("oldFiles/backPage.html", "finalBackPage.pdf")
|
||||||
|
|
||||||
create_pdf_from_html("oldFiles/frontPage.html", "outputFront.pdf")
|
|
||||||
create_pdf_from_html("oldFiles/backPage.html", "outputBack.pdf")
|
|
||||||
create_pdf_from_html("oldFiles/backPage3.html", "outputBack3.pdf")
|
|
||||||
create_qrcode()
|
|
||||||
test("oldFiles/frontPage.html", "finalFrontPage.pdf")
|
|
||||||
test("oldFiles/backPage.html", "finalBackPage.pdf")
|
|
||||||
|
|
||||||
merge_pdfs('finalFrontPage.pdf', 'finalBackPage.pdf', 'combined.pdf')
|
merge_pdfs('finalFrontPage.pdf', 'finalBackPage.pdf', 'combined.pdf')
|
||||||
|
|
||||||
|
# delete temporary files
|
||||||
|
|
||||||
|
subprocess.run(["rm", "finalFrontPage.pdf"])
|
||||||
|
subprocess.run(["rm", "finalBackPage.pdf"])
|
|
@ -53,7 +53,7 @@
|
||||||
Hey, wir haben gerade Dein Paket liebevoll verpackt und konnten es kaum
|
Hey, wir haben gerade Dein Paket liebevoll verpackt und konnten es kaum
|
||||||
erwarten, Dir diese kleine Nachricht zu hinterlassen,
|
erwarten, Dir diese kleine Nachricht zu hinterlassen,
|
||||||
</span>
|
</span>
|
||||||
<b>[NAME]</b><span>.</span>
|
<b>{{CUSTOMER_NAME}}</b><span>.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span>Jeder Code ist ein kleines Dankeschön von uns an Dich, </span>
|
<span>Jeder Code ist ein kleines Dankeschön von uns an Dich, </span>
|
||||||
<b>[NAME]</b
|
<b>{{CUSTOMER_NAME}}</b
|
||||||
><span
|
><span
|
||||||
>, und wir hoffen, dass sie Dein Shopping-Erlebnis noch besser machen.
|
>, und wir hoffen, dass sie Dein Shopping-Erlebnis noch besser machen.
|
||||||
Falls Du Fragen hast oder Unterstützung brauchst, zögere nicht, uns zu
|
Falls Du Fragen hast oder Unterstützung brauchst, zögere nicht, uns zu
|
||||||
|
|
|
@ -1,18 +1,7 @@
|
||||||
{
|
{
|
||||||
"category": "Shinnex",
|
"category": "Shinnex",
|
||||||
"name": "Bestellung",
|
"name": "Bestellung",
|
||||||
"globalInputs": [
|
"globalInputs": [],
|
||||||
{
|
|
||||||
"parameterName": "orderId",
|
|
||||||
"type": "text",
|
|
||||||
"displayName": "Bestellnummer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"parameterName": "customerEmail",
|
|
||||||
"type": "text",
|
|
||||||
"displayName": "E-Mail vom Kunden"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"name": "CRM Customer",
|
"name": "CRM Customer",
|
||||||
|
@ -24,14 +13,22 @@
|
||||||
{
|
{
|
||||||
"parameterName": "orderId",
|
"parameterName": "orderId",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"displayName": "Bestellnummer",
|
"displayName": "Bestellnummer"
|
||||||
"global": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parameterName": "customerEmail",
|
"parameterName": "customerEmail",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"displayName": "E-Mail vom Kunden",
|
"displayName": "E-Mail vom Kunden"
|
||||||
"global": true
|
},
|
||||||
|
{
|
||||||
|
"parameterName": "customerName",
|
||||||
|
"type": "text",
|
||||||
|
"displayName": "Vorname vom Kunden"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameterName": "discountCode",
|
||||||
|
"type": "text",
|
||||||
|
"displayName": "10 % Gutscheincode für den Kunden (in Shopify erstellen)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue