Automatic Rewriting of 728 Product Cards on Webasyst
TL;DR
The Webasyst site had 728 product cards with old descriptions — plain unstructured text. Each needed to be rewritten into a new semantic format with specific HTML classes, and SEO meta tags updated. I built a two-agent pipeline: one writes text according to a strict prompt, the other publishes via the API. Along the way, I had to bypass the hosting WAF, which was blocking requests.
Technology Stack
| Technology | Role |
|---|---|
| Python | Scanner, API clients, orchestrator, validator |
| DeepSeek API | Generation of descriptions and meta tags |
| Webasyst REST API | Reading and writing product cards |
| SQLite / CSV | Storage of statuses and backups |
| BeautifulSoup / regex | Parsing card HTML |
| OAuth 2.0 | Authorization in Webasyst |
Context and Task
There is a site on Webasyst (Shop-Script) — a fabric catalog for a B2B audience: table linen, workwear, restaurant textiles. Hundreds of product cards, each with a description in the old format: plain text with line breaks, no headings, no structure.
In parallel, a new card format appeared on the site. The benchmark is one manually rewritten page. Its description is laid out differently: semantic HTML with headings, fact blocks, and an FAQ section. It looks better, reads easier, and, importantly for SEO, provides search engines with structured content and ready-made micro-answers.
The task sounded simple: bring the remaining 728 cards to the new format. In reality, it's three nested tasks:
- Text rewriting — rewrite the description according to the new structure without inventing facts.
- Publishing — write the new HTML back into the card.
- SEO meta tags — fill in title and meta description, but only where they are empty.
Manually, this is weeks of monotonous work: open a card, copy the characteristics, write the text, paste the HTML, save, check. Multiply by 728.
What I Found Out Before Writing Code
Before building the solution, I thoroughly researched the subject. It took time but paid off: all key decisions were made based on facts, not guesses.
Platform
The site runs on Webasyst / Shop-Script, theme mastershop (v3.5.1.12), admin panel at /webasyst. The main discovery: Shop-Script has a full-fledged REST API through a single api.php endpoint with OAuth 2.0 authorization and methods shop.product.getInfo, shop.product.update, shop.product.search, shop.product.massUpdate. This meant publishing could be automated without fragile browser automation.
Scale
Through the sitemap, I counted 728 product URLs. I checked 15 random cards — all were in the old format. So essentially the entire catalog needed rewriting.
Benchmark Card
I downloaded the benchmark HTML and dissected it down to the last tag. This gave me the exact structure to reproduce.
Old Card
For comparison, I took any unedited card. The difference became obvious.
Old Format vs. New Format
What It Looked Like "Before"
The old description was stored inside <div itemprop="description"> and was plain text with <br /> line breaks. No headings or structure:
<div itemprop="description">
Calico fabric, composition 100% cotton, density 142 g/m2...<br />
Used for sewing bed linen...<br />
...
</div>
Hard for a person to read. Even harder for a search engine: no semantic anchors to grab onto, no ready-made answers to questions.
What It Looks Like "After"
The new format is full-fledged semantic HTML with a strict sequence of sections:
<div itemprop="description">
<p> introductory paragraph: what the fabric is, article number, purpose, style
<p> summary of characteristics: composition, density, width, color
<p> paragraph about the key property (e.g., GO finish)
<p> paragraph about the model's feature (pattern, ornament)
<h2>Key Characteristics</h2>
<div class="facts-wrapper space-btw">
<div class="faq-item">
<h4 class="faq-item__question">…</h4>
<p>…</p>
</div> <!-- ×3 -->
</div>
<h2>Care Recommendations</h2>
<p>…</p>
<h2>Applications</h2>
<p>…</p> ×3
<h3>Frequently Asked Questions about "…" fabric</h3>
<div class="faq-item">
<h4 class="faq-item__question"><b>…</b></h4>
<p>…</p>
</div> <!-- ×5 -->
</div>
Plus, the short description at the top of the card (product-card__summary) was updated.
flowchart TD
A[Old description] -->|plain text with br| B[No structure]
C[New description] --> D[Introductory paragraphs]
C --> E["h2 + facts-wrapper + faq-item"]
C --> F["h2 Care Recommendations"]
C --> G["h2 Applications"]
C --> H["h3 FAQ + faq-item ×5"]
Markers to Distinguish "Old" from "New"
Key finding: the new format can be detected by three CSS classes inside the description block:
faq-itemfaq-item__questionfacts-wrapper
If the card's HTML lacks at least one of these — it's an old card needing a rewrite. A simple deterministic check instead of "looking with your eyes."
Additional fact: the characteristics table (product_features) is identical in both old and new versions. It doesn't need to be touched, but it serves as a source of facts for the text. This is important: the agent must not invent density, composition, or width but take them from there.
Solution Architecture
Initially, the task sounded like "we need two agents: one writes texts, the other posts." I agreed with the core but wrapped it in infrastructure: two agents without a queue, storage, and validation would drown in manual management.
The final pipeline has six components:
flowchart LR
A[Scanner<br>inventory] --> B[Storage<br>statuses and backups]
B --> C[Orchestrator<br>queue, retries]
C --> D[Copywriter Agent<br>LLM]
D --> B
C --> E[Poster Agent<br>Webasyst API]
E --> F[Validator<br>marker check]
F --> B
1. Scanner and Inventory
Walks the sitemap, for each card:
- downloads the HTML;
- checks markers (
faq-item,facts-wrapper); - extracts
product_id(in HTML it's stored asdata-product="1630"), name, article number, URL; - extracts the characteristics table and current description.
The result is a record in storage with status pending. For speed, the scanner is multithreaded: 728 pages one by one is slow, in parallel — minutes.
2. State Storage
A simple table (SQLite or even Google Sheets to start):
| url | product_id | status | old_description_hash | new_html | summary | posted_at | validated |
|---|---|---|---|---|---|---|---|
| … | 1630 | done | 9f2c… | … | … | … | true |
Critically important fields are old_description_hash and the saved copy of the old description. This is the rollback mechanism: if the new text turns out bad, the old one can always be restored.
3. Copywriter Agent
An LLM call with a strict contract:
- input: product JSON (name, article number, characteristics, old description, benchmark as a sample);
- output: strict JSON
{"description_html": "...", "summary_text": "..."}.
Prompt requirements: don't invent characteristics, take facts only from input data, strictly follow the benchmark's HTML structure, maintain the tone of an expert B2B editor.
4. Poster Agent
Accepts the ready HTML, writes it to the product via the API shop.product.update, then passes it to the validator. Before writing, it always backs up the old description.
5. Validator
After posting, re-downloads the card and checks that the marker classes have appeared. Only then does the status become done. If not — error and an alert.
6. Orchestrator
Manages the queue, respects the rate limit, retries on failures, and keeps a log. Processing is done in batches of 50 cards with a pause between batches — this makes it easier to control the process and catch problems early.
Key Decisions
Publishing: API, Not Browser
Three ways to write text to a card, each with its own trade-offs:
| Method | Pros | Cons | Verdict |
|---|---|---|---|
REST API (shop.product.update) |
Fast, stable, mass, easy to rollback | Requires a token with product permissions | Primary |
| Admin panel via Playwright | Works without API access | Slow, fragile, WYSIWYG may strip classes | Fallback |
| Direct MySQL write | Fastest | Dangerous: caches, Shop-Script logic, risk of data corruption | Don't use |
I chose the API. The reason is simple: if you insert HTML through the admin panel's visual editor, it will likely strip the non-standard faq-item and facts-wrapper classes. Through the API, the HTML goes through as-is, without intermediaries.
Client sketch:
import requests
BASE = "https://shop.example.com/api.php"
def shop_call(method: str, params: dict, token: str):
r = requests.post(
f"{BASE}/{method}",
data={**params, "access_token": token},
timeout=30,
)
r.raise_for_status()
data = r.json()
if "error" in data:
raise RuntimeError(data)
return data
# find product by name if no id
found = shop_call("shop.product.search", {"name": "Zhuravinka-3"}, token)
# update description and short description
shop_call("shop.product.update", {
"id": 1630,
"description": new_description_html,
"summary": new_summary_text,
}, token)
SEO Meta Tags: Only Where Empty
A separate requirement: fill in title and meta description only if the fields in the admin panel are empty. Unique, no masks, no domain mention via the | symbol.
The logic is simple and reliable: before generation, the script checks meta_title and meta_description via shop.product.getInfo. Generation and writing are performed only for empty fields. This is a deterministic check, not a visual assessment.
Prompt Design: From the Manual
The project had an AI-SEO manual (63 pages). Instead of an arbitrary prompt, the methodology was extracted from the document and embedded into the prompt:
- short self-contained fragments — each paragraph answers one question;
- "one thought = one paragraph" — no solid walls of text;
- answer patterns — "definition," "cause → effect," "selection criteria";
- FAQ block as ready-made quotable micro-answers — these are exactly what search engines extract into snippets.
The prompt turned out strict: input — JSON with facts, output — JSON with ready HTML, and between them — strict structure rules and a ban on inventing. Plus few-shot: the benchmark in full as a sample.
Problems I Encountered
Here are the non-obvious problems, each requiring a separate solution.
1. "API Doesn't Work" — But It Did
The first attempt to open api.php in a browser gave an error. It looked like "the API is broken." In reality, this is expected behavior: without a token, the API responds with {"error":"token_required"}.
api.php is not a page to view but an entry point for requests. Opening it in a browser is pointless. After obtaining the token, everything worked.
2. Hosting WAF Blocked the Authorization Header
The most challenging case in the project. After obtaining the token, requests with the Authorization: Bearer ... header started returning HTTP 403 from the hosting filter.
This was the hosting's protection (WAF): it blocked exactly that header. curl was also blocked — likely by User-Agent.
The solution was found by trial and error:
- ❌
Authorization: Bearer— 403; - ❌
curl.exe— blocked; - ✅ token in URL (
access_token=...) + browser User-Agent — HTTP 200.
This is a classic WAF bypass: move authorization from the header to a request parameter and mimic a browser. Formally the same OAuth token, but in a form the filter allows through.
# this way — 403 from WAF
headers = {"Authorization": f"Bearer {token}"}
# but this way — 200
params = {"access_token": token}
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
3. Cherry Studio — Not an API Server
Initially, it was planned to run the LLM "through Cherry Studio." The problem is that Cherry Studio is a desktop interface to models, not a server that can be called from a Python script.
The solution — go directly to the provider configured in Cherry Studio (in my case, DeepSeek), with the same endpoint, key, and model. Cherry Studio remains a shell for manual work, while the script calls the API directly.
4. Configuration Errors in .env
Typical configuration errors:
WEBASYST_TOKENcontained not a token but a whole URL likehttps://site/#access_token=...— only the token itself was needed;- variables were named
DEEPSEEK_*, but the config expectedLLM_*— the script simply didn't see them; DEEPSEEK_API_URLcontained the full path/chat/completions, while the client itself appended this suffix — resulting in a double path.
All this is solved with one technique: the config must be resilient. I added support for both naming formats and protection against double paths.
5. Windows Encoding: Error on the ² Symbol
When parsing HTML, the Windows console (cp1251) failed to handle the "²" symbol, and the script crashed. The problem was that output went directly to the console with the wrong encoding.
The solution is simple and universal: don't output Cyrillic and special characters to the console; write the result to a UTF-8 file and read it. This became a rule for all project scripts.
6. Minified HTML — One Line of 53 KB
The benchmark page's HTML turned out to be minified: the entire page body in one line of 53,000 characters. Line-by-line reading is useless.
The solution — parse via Python: read the file entirely and extract the needed fragments by positions and regular expressions. This also gave an exact list of all CSS classes and their usage frequency.
7. Model Hallucinations
A risk that never goes away: the LLM might invent density or composition not present in the characteristics. For a fabric catalog, this is critical — a buyer will make a decision based on an incorrect number.
Protection is two-level. First, a strict rule in the prompt: "use only facts from the JSON." Second, a deterministic post-check: key numbers from the characteristics must appear in the generated text. If the model still invented something — the error is caught during validation.
Project Structure
Everything related to the project went into a separate folder:
webasyst/
├── prompt/ # sources: assignment and AI-SEO book
├── prompts/product_prompt.md # ready copywriter prompt
├── src/
│ ├── config.py # .env loading, resilient to naming formats
│ ├── webasyst_api.py # Webasyst API client
│ ├── scanner.py # sitemap walk + marker check
│ ├── llm_client.py # OpenAI-compatible client for DeepSeek
│ ├── poster.py # posting + backup of old descriptions
│ ├── validator.py # marker check after posting
│ └── pipeline.py # full-cycle orchestrator
├── data/ # reports and processing state
├── README.md # plan + token instructions
├── .env.example # settings template
└── requirements.txt
Each script is a separate stage that can be run manually. pipeline.py ties them into a full automaton.
Copywriter Prompt Framework
This is not the final text but the mandatory blocks from which the working prompt is assembled. It's important enough that I'll put it in a separate fragment:
You are an editor of a fabric catalog for a B2B audience
(HoReCa, uniforms, restaurant textiles).
Given product characteristics (JSON) and the old description.
Generate a NEW description strictly following the benchmark structure:
1) <p> — what the fabric is, article number, purpose, style;
2) <p> — summary of characteristics strictly from JSON;
3) <p> — key property (finish/weave) and its benefit;
4) <p> — model's feature (pattern/color), interior styles;
5) <h2>Key Characteristics</h2>
+ <div class="facts-wrapper space-btw">
with 3 blocks <div class="faq-item"> (h4.faq-item__question + p);
6) <h2>Care Recommendations</h2> + <p>;
7) <h2>Applications</h2> + 3 <p>;
8) <h3>Frequently Asked Questions about "…" fabric</h3>
+ 5 <div class="faq-item"> (question in <b>).
Rules:
- Use only facts from JSON, don't invent anything.
- Classes and section order — strictly as in the benchmark.
- Return JSON: {"description_html": "...", "summary_text": "..."}
- summary_text — 4–6 short lines without HTML.
In production, few-shot is added: the benchmark in full as a sample. One real example stabilizes the model better than any verbal description.
Final Scheme
flowchart TD
A[sitemap-shop.xml] --> B[Scanner]
B --> C{Has faq-item<br>and facts-wrapper?}
C -->|Yes| D[Skip]
C -->|No| E[Extract data<br>id, characteristics, description]
E --> F[Storage: status=pending]
F --> G[Orchestrator<br>batches of 50]
G --> H[Copywriter LLM<br>description_html + summary]
H --> F
G --> I[Check SEO fields<br>getInfo]
I --> J[Poster<br>shop.product.update]
J --> K[Validator<br>re-check markers]
K --> F
Result
The pipeline works in batches of 50 cards with a pause between them. At the time of stopping, 103 cards were processed; the full list is in the project report. Each card goes from scanning to validation automatically.
What the solution provides:
- unified format — all descriptions brought to the benchmark structure with
faq-itemandfacts-wrappermarkers; - SEO meta tags — filled only where empty, always unique, no masks or domain;
- rollback — the old description of each card is saved, any can be restored;
- control — statuses in storage, a report for each card, a pause between batches.
Lessons Learned
- Research before coding. A day spent analyzing the benchmark and old card saved weeks of rework.
- Markers are more reliable than visual assessment. A deterministic check by classes is more accurate than "looking to see if it seems similar."
- API is preferable to the browser. Where an API exists — use it, not click automation.
- WAF is bypassed by the request form. Sometimes a token in the URL works where a header is blocked.
- The config must be resilient. Supporting both variable naming formats and protection against double paths saves hours of debugging.
- Don't trust the model with facts. Hallucinations are caught not by the prompt but by deterministic number checks.
- Encoding is a separate discipline. Write results to a UTF-8 file, not to the console.
Next Steps
- Catch up the remaining batches to the end of the catalog.
- Add title/meta_description updates in the same pass for cards where fields are empty.
- Integrate manual spot-check quality control on every tenth product.
- Move process metrics to a simple dashboard.
