leviroiz.dev Back to the album
PT

Track 01 · CompletedPython and Selenium

Price audit

An API change caused price mismatches in e-commercevariants, across colors and sizes.

Try the audit

101 references corrected245 products audited

The story

Every product has a grid of variants with their own prices. Some prices changed incorrectly, and checking every cell by hand was impractical.

I wrote a Python and Selenium automation that audits each variant, checks inventory and corrects mismatches using the same interface as the store team. It reloads the page after each correction to verify the result.

The tricky part was recovery. The browser can crash, and a partial or repeated correction is worse than no correction. That is why each write is logged before it happens.

Terminal showing the automation checking 245 references, finding 101 mismatches and logging each correction.
The automation running in the public recreation with synthetic data.

The audit resumes from its checkpoint.

Run, stop and resume the audit. The grid marks the items already checked.

Run the audit, stop it midway and try resuming it.
0audited
0mismatches
0corrected and verified
reading
mismatch
corrected and verified
ok
Under the hoodconstraints, steps and details

What could go wrong

  • A correct price hides an error in a neighboring variant.
  • Stock for one variant is used to validate another.
  • A list of mismatches is treated as approval.
  • A crash leaves a partial write or causes a repeat write.

Each correction, step by step

  1. Read the current state and validate the variant grid.
  2. Calculate the target only for approved references.
  3. Log the intended write in a local SQLite journal.
  4. Save through the interface.
  5. Reload and compare prices, variant grids and stock.
  6. Mark the correction as verified.

Four independent steps check prices, check variant grids, match stock and apply corrections. If a run stops before saving, the pending write can resume. If it stops afterward, the automation rereads the screen to verify the save without repeating it. If the state matches neither the original nor the target, the run stops.

Monetary values use Decimal arithmetic. The expected amount and the observed amount are stored separately.

Next trackTOTVS ↔ ViaShop