code structure
parent
3f11e1db83
commit
b436985bc9
|
@ -69,7 +69,7 @@
|
|||
</p>
|
||||
|
||||
<div class="code-box first-item">
|
||||
<span>SYfwa2g</span>
|
||||
<span>{{DISCOUNT_CODE}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -88,7 +88,7 @@
|
|||
</div>
|
||||
|
||||
<div class="container-action">
|
||||
<img class="image-11-icon" alt="" src="./qrcode.png" />
|
||||
<img class="image-11-icon" alt="" src="./5euro.png" />
|
||||
|
||||
<div>
|
||||
<div class="status-box">
|
||||
|
@ -130,7 +130,7 @@
|
|||
</div>
|
||||
|
||||
<div class="container-action">
|
||||
<img class="image-11-icon" alt="" src="./qrcode.png" />
|
||||
<img class="image-11-icon" alt="" src="./10euro.png" />
|
||||
|
||||
<div>
|
||||
<div class="status-box">
|
||||
|
|
|
@ -1,48 +1,56 @@
|
|||
import requests
|
||||
import sys
|
||||
import json
|
||||
import qrcode
|
||||
|
||||
# DEFINITIONS
|
||||
|
||||
endpoint_url = "https://devdash.ex.umbach.dev/api/v1/crm"
|
||||
api_key = "uY1DTUog-Iax7-ydc4-dP9V-NON1xsbTGH1I"
|
||||
|
||||
headers = {
|
||||
"X-Api-Key": api_key,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
ENDPOINT_URL = "https://devdash.ex.umbach.dev/api/v1/crm"
|
||||
API_KEY = "uY1DTUog-Iax7-ydc4-dP9V-NON1xsbTGH1I"
|
||||
QR_CODE_URL = "https://devdash.ex.umbach.dev/api/v1/crm/link/"
|
||||
|
||||
# MAIN
|
||||
|
||||
headers = {
|
||||
"X-Api-Key": API_KEY,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
json_object = json.loads(sys.argv[1])
|
||||
customerEmail = json_object["customerEmail"]
|
||||
customerName = json_object["customerName"]
|
||||
discountCode = json_object["discountCode"]
|
||||
orderId = json_object["orderId"]
|
||||
|
||||
if customerEmail is None:
|
||||
print("customerEmail is required")
|
||||
if (customerEmail is None
|
||||
or orderId is None
|
||||
or customerName is None
|
||||
or discountCode is None):
|
||||
print("Missing required parameters")
|
||||
sys.exit(1)
|
||||
|
||||
customerEmail = customerEmail["value"]
|
||||
customerName = customerName["value"]
|
||||
discountCode = discountCode["value"]
|
||||
orderId = orderId["value"]
|
||||
|
||||
|
||||
def CreateCrmCustomer():
|
||||
response = requests.post(
|
||||
url=f"{endpoint_url}/customer/create",
|
||||
url=f"{ENDPOINT_URL}/customer/create",
|
||||
headers=headers,
|
||||
json={
|
||||
"FirstName": "Shopify Customer",
|
||||
"Email": customerEmail,
|
||||
"LeadOrigin": "Shopify Customer added by GroupTask",
|
||||
})
|
||||
|
||||
print(f"CreateCrmCustomer response status code {response.status_code}")
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"CreateCrmCustomer req error {response.status_code}")
|
||||
sys.exit(1)
|
||||
|
||||
print(response.status_code)
|
||||
print(response.json())
|
||||
|
||||
return response.json()["Id"]
|
||||
|
||||
|
||||
|
@ -50,7 +58,7 @@ def CheckIfCrmCustomerExists():
|
|||
print(f"Checking if customer exists: {customerEmail}")
|
||||
|
||||
response = requests.post(
|
||||
url=f"{endpoint_url}/customer",
|
||||
url=f"{ENDPOINT_URL}/customer",
|
||||
headers=headers,
|
||||
json={"Email": customerEmail} # Hier json verwenden, um JSON-Daten zu senden
|
||||
)
|
||||
|
@ -74,6 +82,7 @@ def CheckIfCrmCustomerExists():
|
|||
customerId = response.json()[0]["Id"]
|
||||
|
||||
CreateCrmActivityLink(customerId=customerId)
|
||||
GetCustomerActivityLinks(customerId=customerId)
|
||||
|
||||
|
||||
def CreateCrmActivityLink(customerId):
|
||||
|
@ -81,23 +90,119 @@ def CreateCrmActivityLink(customerId):
|
|||
|
||||
def req(type):
|
||||
response = requests.post(
|
||||
url=f"{endpoint_url}/links",
|
||||
headers=headers,
|
||||
json={
|
||||
"CustomerId": customerId,
|
||||
"Name": f"Shopify Order #{orderId} - {type}",
|
||||
"Url": "https://www.example.com"
|
||||
})
|
||||
url=f"{ENDPOINT_URL}/links",
|
||||
headers=headers,
|
||||
json={
|
||||
"CustomerId": customerId,
|
||||
"Name": f"Shopify Order #{orderId} - {type}",
|
||||
"Url": "https://www.example.com"
|
||||
})
|
||||
|
||||
print(f"CreateCrmActivityLink response status code {response.status_code} for {type}")
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"CreateCrmActivityLink req error {response.status_code}")
|
||||
sys.exit(1)
|
||||
|
||||
print(response.status_code)
|
||||
|
||||
req("5 € 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()
|
||||
|
||||
ReplaceHtmlVariables()
|
||||
|
|
|
@ -1,43 +1,8 @@
|
|||
import os
|
||||
import pdfkit
|
||||
import qrcode
|
||||
import subprocess
|
||||
import PyPDF2
|
||||
import sys
|
||||
|
||||
|
||||
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):
|
||||
def createPdf(sourceHtml, outputPdf):
|
||||
command = [
|
||||
"google-chrome-stable",
|
||||
"--headless",
|
||||
|
@ -51,10 +16,15 @@ def test(sourceHtml, outputPdf):
|
|||
]
|
||||
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
_, stderr = process.communicate()
|
||||
|
||||
print("STDOUT:", stdout)
|
||||
print("STDERR:", stderr)
|
||||
if process.returncode != 0:
|
||||
print("Error creating PDF")
|
||||
print(stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print("PDF created successfully")
|
||||
|
||||
|
||||
def merge_pdfs(pdf1_path, pdf2_path, output_path):
|
||||
# Öffne die beiden PDF-Dateien
|
||||
|
@ -81,14 +51,12 @@ def merge_pdfs(pdf1_path, pdf2_path, output_path):
|
|||
pdf_writer.write(output_file)
|
||||
|
||||
if __name__ == "__main__":
|
||||
directory = "oldFiles/" # Aktuelles Verzeichnis
|
||||
list_files_in_directory(directory)
|
||||
createPdf("oldFiles/frontPage.html", "finalFrontPage.pdf")
|
||||
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
|
||||
erwarten, Dir diese kleine Nachricht zu hinterlassen,
|
||||
</span>
|
||||
<b>[NAME]</b><span>.</span>
|
||||
<b>{{CUSTOMER_NAME}}</b><span>.</span>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
|
@ -84,7 +84,7 @@
|
|||
|
||||
<p>
|
||||
<span>Jeder Code ist ein kleines Dankeschön von uns an Dich, </span>
|
||||
<b>[NAME]</b
|
||||
<b>{{CUSTOMER_NAME}}</b
|
||||
><span
|
||||
>, und wir hoffen, dass sie Dein Shopping-Erlebnis noch besser machen.
|
||||
Falls Du Fragen hast oder Unterstützung brauchst, zögere nicht, uns zu
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
{
|
||||
"category": "Shinnex",
|
||||
"name": "Bestellung",
|
||||
"globalInputs": [
|
||||
{
|
||||
"parameterName": "orderId",
|
||||
"type": "text",
|
||||
"displayName": "Bestellnummer"
|
||||
},
|
||||
{
|
||||
"parameterName": "customerEmail",
|
||||
"type": "text",
|
||||
"displayName": "E-Mail vom Kunden"
|
||||
}
|
||||
],
|
||||
"globalInputs": [],
|
||||
"tasks": [
|
||||
{
|
||||
"name": "CRM Customer",
|
||||
|
@ -24,14 +13,22 @@
|
|||
{
|
||||
"parameterName": "orderId",
|
||||
"type": "text",
|
||||
"displayName": "Bestellnummer",
|
||||
"global": true
|
||||
"displayName": "Bestellnummer"
|
||||
},
|
||||
{
|
||||
"parameterName": "customerEmail",
|
||||
"type": "text",
|
||||
"displayName": "E-Mail vom Kunden",
|
||||
"global": true
|
||||
"displayName": "E-Mail vom Kunden"
|
||||
},
|
||||
{
|
||||
"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