handling oldFiles

main
alex 2024-05-03 22:47:45 +02:00
parent 68c587f30a
commit 53c84dd613
6 changed files with 26 additions and 6 deletions

View File

@ -83,6 +83,8 @@ def replacePlaceholder():
if __name__ == "__main__": if __name__ == "__main__":
utils.move_files_back_from_old_files()
print(f"Creating package label for {customer_first_name}") print(f"Creating package label for {customer_first_name}")
downloadFile(shipping_label_url, "label.png") downloadFile(shipping_label_url, "label.png")

View File

@ -4,6 +4,13 @@ import yaml
import smtplib import smtplib
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from libs.utils import utils
utils.move_files_back_from_old_files()
STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/" STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/"

View File

@ -3,7 +3,6 @@ import sys
import json import json
import qrcode import qrcode
import subprocess import subprocess
import PyPDF2
import sys import sys
import os import os
@ -115,7 +114,6 @@ def CreateCrmActivityLink(customerId):
print(f"CreateCrmActivityLink req error {response.status_code}") print(f"CreateCrmActivityLink req error {response.status_code}")
sys.exit(1) sys.exit(1)
req("10 % Gutschein", "https://shinnex.de") req("10 % Gutschein", "https://shinnex.de")
req("5 € Gutschein", productUrl) req("5 € Gutschein", productUrl)
req("10 € Gutschein", f"https://docs.google.com/forms/d/e/1FAIpQLSd2GXFbidzazuQnh_Lf2mgeA1npuwHkWjsdmjrxDmSkDQTfew/viewform?entry.347359844={orderId}") req("10 € Gutschein", f"https://docs.google.com/forms/d/e/1FAIpQLSd2GXFbidzazuQnh_Lf2mgeA1npuwHkWjsdmjrxDmSkDQTfew/viewform?entry.347359844={orderId}")
@ -141,7 +139,7 @@ def create_qrcode(type, id):
img.save(f"./{type}.png") img.save(f"./{type}.png")
# Display the generated QR code image # Display the generated QR code image
img.show() #img.show()
def GetCustomerActivityLinks(customerId): def GetCustomerActivityLinks(customerId):
@ -220,7 +218,6 @@ def createPdf(sourceHtml, outputPdf):
"--headless", "--headless",
"--no-sandbox", "--no-sandbox",
"--disable-gpu", "--disable-gpu",
"--debug=1",
"--print-to-pdf=" + outputPdf, "--print-to-pdf=" + outputPdf,
"--run-all-compositor-stages-before-draw", "--run-all-compositor-stages-before-draw",
"--virtual-time-budget=10000", "--virtual-time-budget=10000",
@ -237,6 +234,8 @@ def createPdf(sourceHtml, outputPdf):
if __name__ == "__main__": if __name__ == "__main__":
utils.move_files_back_from_old_files()
CheckIfCrmCustomerExists() CheckIfCrmCustomerExists()
ReplaceHtmlVariables() ReplaceHtmlVariables()

View File

@ -41,7 +41,6 @@ def createPdf(sourceHtml, outputPdf):
"--headless", "--headless",
"--no-sandbox", "--no-sandbox",
"--disable-gpu", "--disable-gpu",
"--debug=1",
"--print-to-pdf=" + outputPdf, "--print-to-pdf=" + outputPdf,
"--run-all-compositor-stages-before-draw", "--run-all-compositor-stages-before-draw",
"--virtual-time-budget=10000", "--virtual-time-budget=10000",
@ -57,6 +56,8 @@ def createPdf(sourceHtml, outputPdf):
sys.exit(1) sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
utils.move_files_back_from_old_files()
# replace placeholders in index.js # replace placeholders in index.js
p_type_id = product_type_id.split(" ")[0].split("#")[1] p_type_id = product_type_id.split(" ")[0].split("#")[1]

View File

@ -1,5 +1,7 @@
import subprocess import subprocess
import PyPDF2 import PyPDF2
import os
import shutil
def clear_workspace(files): def clear_workspace(files):
if not files or not isinstance(files, list) or len(files) == 0: if not files or not isinstance(files, list) or len(files) == 0:
@ -32,3 +34,12 @@ def merge_pdfs(pdf1_path, pdf2_path, output_path):
# save the combined PDF # save the combined PDF
with open(output_path, 'wb') as output_file: with open(output_path, 'wb') as output_file:
pdf_writer.write(output_file) pdf_writer.write(output_file)
# If a script failes the files are moved to the old_files directory so we need to move them back so that the paths defined in the files are correct
def move_files_back_from_old_files():
# check if old_files directory exists and move files back
if os.path.exists("oldFiles"):
for file in os.listdir("oldFiles"):
shutil.move(os.path.join("oldFiles", file), file)
os.rmdir("oldFiles")