Stephan86 Claude Sonnet 4.6 commited on
Commit
d465d27
·
1 Parent(s): 3c560e0

feat: add brand name field — last column in CSV

Browse files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (3) hide show
  1. app.py +4 -3
  2. core/csv_writer.py +7 -7
  3. static/index.html +5 -0
app.py CHANGED
@@ -32,7 +32,7 @@ MAX_PDF_MB = 50
32
 
33
 
34
  def _run_job(job_id: str, pdf_path: str, page_from: int, page_to: int,
35
- default_unit: str, password: str):
36
  try:
37
  def _progress(done, total):
38
  _jobs[job_id]["progress"] = f"{done}/{total}"
@@ -46,7 +46,7 @@ def _run_job(job_id: str, pdf_path: str, page_from: int, page_to: int,
46
 
47
  out = tempfile.NamedTemporaryFile(suffix=".csv", delete=False)
48
  out.close()
49
- to_csv(articles, out.name)
50
  _jobs[job_id] = {
51
  "status": "done",
52
  "result": out.name,
@@ -103,6 +103,7 @@ async def extract(
103
  page_from: int = Form(1),
104
  page_to: int = Form(10),
105
  default_unit: str = Form("Pièce"),
 
106
  password: str = Form(""),
107
  ):
108
  if not pdf.filename.lower().endswith(".pdf"):
@@ -137,7 +138,7 @@ async def extract(
137
  loop.run_in_executor(
138
  _executor,
139
  _run_job,
140
- job_id, pdf_path, page_from, page_to, default_unit, password,
141
  )
142
 
143
  return JSONResponse({"job_id": job_id})
 
32
 
33
 
34
  def _run_job(job_id: str, pdf_path: str, page_from: int, page_to: int,
35
+ default_unit: str, brand: str, password: str):
36
  try:
37
  def _progress(done, total):
38
  _jobs[job_id]["progress"] = f"{done}/{total}"
 
46
 
47
  out = tempfile.NamedTemporaryFile(suffix=".csv", delete=False)
48
  out.close()
49
+ to_csv(articles, out.name, brand)
50
  _jobs[job_id] = {
51
  "status": "done",
52
  "result": out.name,
 
103
  page_from: int = Form(1),
104
  page_to: int = Form(10),
105
  default_unit: str = Form("Pièce"),
106
+ brand: str = Form(""),
107
  password: str = Form(""),
108
  ):
109
  if not pdf.filename.lower().endswith(".pdf"):
 
138
  loop.run_in_executor(
139
  _executor,
140
  _run_job,
141
+ job_id, pdf_path, page_from, page_to, default_unit, brand, password,
142
  )
143
 
144
  return JSONResponse({"job_id": job_id})
core/csv_writer.py CHANGED
@@ -1,18 +1,18 @@
1
  import pandas as pd
2
 
3
- _COLUMNS = ["Référence", "Désignation", "Prix TTC", "Unité"]
4
-
5
-
6
- def to_csv(articles: list[dict], output_path: str) -> str:
7
  """Write articles to a semicolon-separated CSV compatible with EBP Gestion Commerciale."""
8
  rows = []
9
  for a in articles:
10
- rows.append({
11
  "Référence": a.get("code", ""),
12
  "Désignation": a.get("libelle", ""),
13
  "Prix TTC": float(a.get("prix_ttc") or 0),
14
  "Unité": a.get("unite", ""),
15
- })
16
- df = pd.DataFrame(rows, columns=_COLUMNS)
 
 
 
17
  df.to_csv(output_path, index=False, sep=";", encoding="utf-8-sig")
18
  return output_path
 
1
  import pandas as pd
2
 
3
+ def to_csv(articles: list[dict], output_path: str, brand: str = "") -> str:
 
 
 
4
  """Write articles to a semicolon-separated CSV compatible with EBP Gestion Commerciale."""
5
  rows = []
6
  for a in articles:
7
+ row = {
8
  "Référence": a.get("code", ""),
9
  "Désignation": a.get("libelle", ""),
10
  "Prix TTC": float(a.get("prix_ttc") or 0),
11
  "Unité": a.get("unite", ""),
12
+ "Marque": brand,
13
+ }
14
+ rows.append(row)
15
+ columns = ["Référence", "Désignation", "Prix TTC", "Unité", "Marque"]
16
+ df = pd.DataFrame(rows, columns=columns)
17
  df.to_csv(output_path, index=False, sep=";", encoding="utf-8-sig")
18
  return output_path
static/index.html CHANGED
@@ -261,6 +261,11 @@
261
  </select>
262
  </label>
263
 
 
 
 
 
 
264
  <label style="grid-column: 1 / -1;">
265
  Mot de passe PDF <span>(optionnel — si le fichier est protégé)</span>
266
  <input type="password" name="password" placeholder="Laisser vide si non protégé" autocomplete="off" />
 
261
  </select>
262
  </label>
263
 
264
+ <label style="grid-column: 1 / -1;">
265
+ Nom de la marque <span>(ajouté sur chaque ligne du CSV)</span>
266
+ <input type="text" name="brand" placeholder="ex : Camengo, Casamance…" autocomplete="off" />
267
+ </label>
268
+
269
  <label style="grid-column: 1 / -1;">
270
  Mot de passe PDF <span>(optionnel — si le fichier est protégé)</span>
271
  <input type="password" name="password" placeholder="Laisser vide si non protégé" autocomplete="off" />