Every shipment since a date, all pages (needs from the docs: D4 paging)
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..de1df19 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -1,6 +1,7 @@
"""Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
from datetime import date
+from shop import tern
from shop.cart import Cart
from shop.orders import Order
@@ -23,7 +24,16 @@ def book(order: Order, service: str) -> str:
def shipments_since(day: date) -> list[dict]:
"""Every Tern shipment created on or after day, as Tern describes them."""
- raise NotImplementedError
+ shipments: list[dict] = []
+ params = {"created_since": day.isoformat()}
+ while True:
+ status, body = tern.call("GET", "/v2/shipments", params=params)
+ if status != 200:
+ raise RuntimeError(f"Tern shipments listing failed: {status} {body}")
+ shipments.extend(body["shipments"])
+ if not body.get("next_cursor"):
+ return shipments
+ params = {"created_since": day.isoformat(), "cursor": body["next_cursor"]}
def order_status(shipment_id: str) -> str: