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, get a short Slack alert, marked letter or parcel, when an order lands, and ask a Slack bot for the cards to pull for the oldest orders. 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, and the Slack bot keeps its one library in a virtual environment of its own.
- 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 now come in as scanner exports, one CSV per batch named for its batch number, dropped in an intake folder; one run takes every batch waiting there, or a numbered range of them, with one download of the marketplace’s public price list, one review of every card, one upload, one container sync and one ledger booking. Nothing is asked that the files or the workbook already answer: finish, grade and language come from the export, the purchase a lot belongs to is read from a cell on the workbook, and no external card database is called. Each card is matched in the price list by set code and collector number, and the name must agree too, so a wrong number can never list the wrong card. The export’s own price is checked against the marketplace’s market price first, with no markup on either side, and every difference is flagged; only then is the markup applied, to the marketplace’s price. Each original export is kept beside the batch files and synced to the container with them, as a second copy of the scan. A dry-run mode runs the whole chain, price check, batch files, upload plan, the container’s batch tags and the ledger lookup, with nothing sent. The earlier hand route, a working spreadsheet of set codes and collector numbers priced from the same feed, still exists but is no longer needed.
- 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 short Slack alert per order, with an @channel mention so it reaches the phone: platform, card count, total, and an envelope or a package icon for whether the order goes as an untracked letter or a tracked parcel. A Slack bot on the same container answers two words typed in a private channel. `pull` asks how many orders to take, then lists every copy of the oldest ones in box order, one checkbox per copy. `sort` gives the same lines with the order each card goes to. The pull is frozen, so the printed packing slips and stickers cover exactly those orders, numbered the same way. The poller polls and the bot connects outbound, so nothing in the lab listens on the internet.
- 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, then asks the container’s own order watcher how many listings it tags for each new batch and compares that with the PC, so the order alerts are known to name the box before the first sale. A sync is tried three times and a booking twice; anything still failing is kept and done first by the next run, so there is never a command to remember. 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
- 01Pulling part of the orders must not move a card to another box.
Each copy’s box and slot are worked out from how many copies of that card have already sold, oldest order first. Cutting the order list down to the oldest twenty before that count would hand a copy to the wrong slot whenever a newer order had already been booked. The slots are now worked out over every unshipped order first, and only then is the list cut, so a copy keeps the slot a full pull gives it.
- 02One mislabelled card held 35 batches back.
The scanner exported an etched-foil card as plain foil, with the etched finish only in the card’s name. The marketplace answered the upload with success, an empty list of written items and an empty list of rejections, and wrote none of that batch. The intake already treated success with nothing in the written list as a failure, so nothing was falsely reported live. But it kept every file of the run waiting, including the 34 batches that had listed. Re-sending the batch one card per request isolated the card. The finish is now also read from the name, and one card per request is the documented way to find a bad card. The batch map keeps that re-run from adding copies twice.
- 03The scanner files tokens under the main set’s code.
A Treasure token exported as the main set’s card 17, and in that set card 17 is a different, real card. Matching on set and number alone would have listed the wrong card at the token’s price. A token row now tries the token set first, and every match must also agree on the card’s name, or the row is left out and reported.
- 04The 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.
- 05The 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.
- 06A 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.
- 07A 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.
- 08The 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.
- 09Two 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.
- 10A 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.
- 11Splitting 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.
- 12The 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.
- 13The 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.
- 14Moving 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.
- 15The 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.
- 16A 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.