MAGIC
A Magic: The Gathering singles store on Mana Pool, run as a scripted pipeline: scan a bought collection into numbered batches, remap the grades honestly, bulk-upsert the listings through the API, and get a Slack message with the batch numbers, ship-by date, envelope address and pull list when an order lands. The build is gated on evidence rather than enthusiasm — no database until ten orders have shipped.
Lot one is live: ten batches listed through the API with grades intact and every listing tagged with the box it came from, after a quantity bug was caught and repaired before it cost a sale. Order alerts now run unattended on a lab container, proven end to end with a labelled test order through the real code and the real Slack channel. Packing slips, address stickers and thank-you cards print from the PC, two prompts for a whole night of orders. The ledger, the intake runbook and the stale-listing reprice ladder are written. A day-30 gate on 2026-11-13 decides whether any of it continues.
// problem
Turn a box of bought cards into correctly graded, correctly priced listings without overselling stock that has already sold — and without building a pipeline before there is any evidence that the buying works.
// limitations
- Standard library only in the Python that lists cards and watches orders. The box that lists cards gets no pip install; only the two spreadsheet helpers on the PC use a spreadsheet library.
- No database schema until ten orders have shipped; no custom repricer until fifty orders and two manual reprice passes.
- The marketplace owns quantity, the repo owns cost basis. A reprice always sends a null quantity and writes price only.
- Shipping rates are set by the marketplace and identical for every seller, so the margin is made at the buy, not at the sale.
- Nothing is sent without an explicit --apply. The API token never reaches stdout, a report, or a traceback.
- The batch field is visible to every API user, so it carries a box number and never cost, supplier, or margin data.
- One writer per record: the container owns which copies have sold, the PC owns what each batch added, and a sync merges the two instead of copying one over the other.
// infrastructure used
- The OpenAPI document is the reference, not the docs page: the rendered docs are a JavaScript shell that yields nothing to a fetcher, so four Node tools inventory the endpoints, search the spec for a concept, and print resolved request and response schemas.
- An intake script maps a scanner CSV through an explicit condition table and bulk-upserts up to 2,000 items per call, carrying an internal batch number in the one seller-writable field that is echoed back on order lines.
- Cards can also come in by hand instead of by scanner: a working spreadsheet of set codes and collector numbers is priced from the marketplace’s public market-price feed, asking first whether the list holds foils, then turned into a numbered batch file in the scanner’s format and handed to the same intake. The sheet holds one batch of up to a hundred cards above a fixed end row, with dropdowns for each card’s grade, printed language and stamp; a blank grade is taken as near mint and a blank language as English, so nothing is asked that the sheet already answers. A stamped card is a separate printing in the set’s promo set, so marking a card as prerelease- or promo-pack-stamped swaps in that printing before it is priced, and the finish settles which stamp is meant when only one exists in it; when the card was printed with both stamps, a link to the card’s marketplace page beside the row names the exact printing; where one collector number covers both an English card and a Japanese alternate-art one, the English art is used unless the row’s language says Japanese; a printing with no market price falls back to a price typed on the sheet, then to the lowest near-mint listing, and is flagged for review; the batch step refuses a stamped row that was never swapped, so it cannot list as the plain card. Before anything is sent, every card is shown for review: prices the feed lacked are typed in, any row’s price, grade or language can be corrected, and cards that will not list are flagged with the reason; only the confirmed list is written to the batch file and listed, and the sheet is cleared for the next batch.
- Uploads are additive: the script reads live inventory first and sends live quantity plus the copies this batch has not added yet, with a batch map on disk that makes a re-run a no-op and never relists a sold copy.
- A poller on its own Proxmox container checks the unshipped-order worklist every five minutes and posts one Slack message per order, with an @channel mention so it reaches the phone — batches, ship-by date, shipping method, the envelope address as a copy-paste block, and a pull list that names the box and slot of every copy. It polls outbound, so nothing in the lab listens on the internet for an order.
- Order paperwork prints from the PC straight to a Wi-Fi inkjet over IPP, with no driver: thank-you cards in bulk ahead of a run of orders, five per feeder load, then the night’s orders by stock. The marketplace’s packing slips, saved as PDFs singly or joined into one, are the list of what to print: each order is found by the order number heading its first page, a long order’s later pages stay with it, and a joined PDF is split into one file per order first. After one prompt to load the 4x6 labels, every slip goes out as its own job, each sent a few seconds after the one before finishes, with no prompt between them; only once the last has finished does one more prompt send every address as a single job of 2x4 stickers, from the next free one on the part-used sheet, carrying onto fresh sheets behind it, with the position kept for the next run. Then the slips are filed. The printer takes no PDF, so each page is drawn at 600 dpi and sent as lossless PWG raster, carrying its own paper size and type.
- An Excel workbook carries the money: purchases to batches to sales, cost allocated pro-rata by scanned market value, with a PowerShell importer writing each order’s real fee and shipping figures off the API. Every upload books its batch on the workbook and syncs the container in the same run, asking which purchase it came from only when the workbook does not already know. The sales sheet reads its own row limit off the workbook and, when an import would run past it, grows itself to at least double, backup first, instead of stopping part-way.
- A local stub of the marketplace API backs 130 checks across three suites — partial success, external-id conflicts, 429 with Retry-After, additive uploads, refund-free order import, and print jobs a stub printer decodes back to the pixel — so none of it is rehearsed against the live store or on paper.
// lessons learned
- 01The price feed sometimes answered from a stale or empty copy.
The marketplace serves its 50 MB price list through a CDN that keeps a copy for ten minutes, and now and then that copy is empty or behind the origin. When the CDN answers from its copy, the fetch now also asks the marketplace directly past the cache, compares the two lists’ timestamps and uses the newer one, and says which it used, so a price never comes from an out-of-time list without the run saying so.
- 02The ink would not dry on the shipping envelopes.
The card mailers are thin cardboard with a coated, printed face, and an inkjet’s dye ink dries by soaking into bare paper, so it sat wet on top and smeared. No print setting fixes the stock. Addresses move to inkjet labels at two to six cents per order, and the first fix for blurry text, sending lossless 600 dpi raster instead of a 300 dpi JPEG, stays.
- 03A second batch holding the same card wiped the first batch’s copies.
Bulk upsert sets quantity absolutely, so the last batch to upload a card silently overwrote the earlier ones: 286 of 447 cards were live and nothing had errored. Uploads now read live quantity and add to it, a batch map records what each box contributed, and a reconcile pass put the 161 missing copies back.
- 04A fee model built from memory set the listing floor three times too high.
The fixed payment fee is charged once per order, not per card, and shipping revenue had been left out entirely — which had made cheap singles look structurally unprofitable. Re-derived from the published fee and shipping schedules, a lone card breaks even near five cents, and the real limit is minutes per order.
- 05The no-code CSV route silently downgrades the entire inventory.
The scanner’s near-mint grade imports as the marketplace’s lightly-played — every grade shifts one notch. That single fact is the reason any pipeline code exists here: the API takes an explicit condition and does not shift it.
- 06Two bugs surfaced in the tests rather than in review.
A price-only run sent neither price nor quantity, and a conflict retry wrote a quantity during a reprice — the one operation that can resurrect sold copies. Both now have assertions against a local stub of the API.
- 07A research pass concluded the sales data did not exist.
It had been sourced from a third-party client library instead of the spec. Grepping the real OpenAPI document found per-card recent sales, a writable external id that round-trips onto orders, and fully specified webhook signing — three impossible things in one afternoon.
- 08Splitting a lot’s cost evenly across its cards corrupted the only question the ledger exists to answer.
An even split gives every card the same basis, which makes a cheap common a guaranteed paper loss and a rare look like a miracle. Cost is allocated pro-rata by scanned market value instead, so "was that lot worth buying" stays answerable.
- 09The marketplace has no idea how long anything has been listed.
A listing carries no creation date and the server-side repricer cannot filter by age or by batch, so a stale-inventory policy cannot live in the platform. A batch is uploaded in one session, which makes a batch an age cohort — the age ladder runs off the batch tag and the batch date.
- 10The capital plan was broken on day two.
Three lots, about $550, bought before a single lot had been scored against the buy-price rule the whole plan rests on. The tranche ladder was replaced with one tranche and no further buying until the day-30 gate, and recorded as an override rather than smoothed into a forecast.
- 11Moving the notifier off the PC split one shelf record into two.
Each posted order marks its copies sold in a batch map, but new batches are scanned on the PC. Copying the PC’s map over would have undone every sale the container booked. The sync now takes new batches from the PC and keeps the container’s sold counts, under the same lock as the cron job.
- 12The container went deaf to DNS on the reboot that renamed it.
The hypervisor was told not to touch the resolver file, but the DHCP client was not, and it put back a LAN resolver that never answers this container. A dry run caught it before any order was missed; the DHCP client now pins the working resolver, and a second reboot proved it.
- 13A typo in a batch label would have orphaned its sales silently.
The ledger joins sales to batches on exact text, so B12 instead of B012 lists perfectly well and then loses the money trail. Labels are refused unless they are a B plus exactly three digits.