asdf
All checks were successful
Deploy App to Docker / deploy (push) Successful in 31s

This commit is contained in:
zman 2025-04-08 13:26:12 -04:00
parent 1bb842ea3f
commit 029c28166e
2 changed files with 44 additions and 21 deletions

View File

@ -12,6 +12,7 @@ from weasyprint import HTML
import json import json
import time import time
import re import re
import csv
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -271,30 +272,52 @@ class TCGPlayerAPIService:
return output_filename return output_filename
def get_address_labels_csv(self, order_ids: list[str]):
url = f"{self.config.ORDER_BASE_URL}/shipping/export{self.config.API_VERSION}"
payload = {
"orderNumbers": order_ids,
"timezoneOffset": -4
}
response = self.requests_util.send_request(url, method='POST', cookies=self.cookies, json=payload)
if response:
# get filename from response headers
header = response.headers.get('Content-Disposition', '')
match = re.search(r'filename="?([^";]+)"?', header)
filename = match.group(1) if match else f'shipping{datetime.now().strftime("%Y%m%d_%H%M%S")}.csv'
output_filename = f'/app/tmp/{filename}'
# save file to disk
with open(output_filename, 'wb') as f:
f.write(response.content)
return output_filename
def get_address_labels_pdf(self, order_ids: list[str]): def get_address_labels_pdf(self, order_ids: list[str]):
shipping_csv_filename = self.get_address_labels_csv(order_ids)
with open(shipping_csv_filename, 'r') as f:
reader = csv.DictReader(f)
orders = {}
for row in reader:
order_id = row.pop('Order #')
orders[order_id] = row
labels_html = [] labels_html = []
for order_id in order_ids: for order in orders:
order = self.get_order(order_id) if float(order['Value of Products']) >49.99:
continue
if order: # Extract relevant information from the order
try: order_info = {
# Extract relevant information from the order "recipient_name": order['FirstName'] + ' ' + order['LastName'],
order_info = { "address_line1": order['Address1'],
"recipient_name": order['shippingAddress']['recipientName'], "address_line2": order['Address2'] if 'Address2' in order else '',
"address_line1": order['shippingAddress']['addressOne'], "city": order['City'],
"address_line2": order['shippingAddress'].get('addressTwo', ''), "state": order['State'],
"city": order['shippingAddress']['city'], "zip_code": order['PostalCode'],
"state": order['shippingAddress']['territory'], "return_address_path": self.return_address_png
"zip_code": order['shippingAddress']['postalCode'], }
"return_address_path": self.return_address_png
}
# Render the label HTML using the template # Render the label HTML using the template
labels_html.append(self.address_label_template.render(order_info)) labels_html.append(self.address_label_template.render(order_info))
except KeyError as e:
print(f"Missing field in order {order_id}: {e}")
continue
if labels_html: if labels_html:
# Combine the rendered labels into one HTML string # Combine the rendered labels into one HTML string

View File

@ -18,7 +18,7 @@ curl -X POST "http://192.168.1.41:8000/api/boxes/d95d26a8-1f82-47f2-89fa-3f88a46
curl -X POST "http://192.168.1.41:8000/api/processOrders" \ curl -X POST "http://192.168.1.41:8000/api/processOrders" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"order_ids": ["E576ED4C-EBD55A-27AE6","E576ED4C-CC32F2-76408"]}' -d '{"order_ids": ["E576ED4C-AD8CC8-9E57E","E576ED4C-2EC48E-7F185","E576ED4C-9B72C2-5E208","E576ED4C-67DAA6-B06B5","E576ED4C-7E52E0-CCE11","E576ED4C-572216-87C96","E576ED4C-37BADB-8BE45","E576ED4C-2D9E83-89C64","E576ED4C-C8080B-8066C","E576ED4C-A41099-E4F92","E576ED4C-2B5122-5E719","E576ED4C-95BB1D-07DDA","E576ED4C-1CF99A-20072","E576ED4C-342542-28CDB","E576ED4C-42720B-514DB","E576ED4C-911CB9-15174","E576ED4C-EBD55A-27AE6","E576ED4C-CC32F2-76408","E576ED4C-45328B-E65B4","E576ED4C-1F26F5-84367","E576ED4C-1D4FE5-71100","E576ED4C-BCEC53-A7CF2","E576ED4C-132791-5AF2E"]}'
curl -X POST "http://192.168.1.41:8000/api/processOrders" \ curl -X POST "http://192.168.1.41:8000/api/processOrders" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \