Skip to content

Commit a0c83a9

Browse files
aborrusoclaude
andcommitted
Release v2.1.9: fix progress messages for OpenData fallback
- Remove misleading error when caricaAKN unavailable - Add progress indicators: initial message, animated dots during polling, success message - Show progress on stderr even when output goes to stdout - Suppress only with explicit --quiet flag - Update LOG.md Fixes confusing UX where users thought command was stuck Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 8853520 commit a0c83a9

6 files changed

Lines changed: 41 additions & 19 deletions

File tree

LOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
Questo file documenta gli avanzamenti significativi e le decisioni chiave del progetto `normattiva_2_md`.
44

5+
## 2026-01-29
6+
7+
### Fix messaggi di progresso fallback OpenData
8+
9+
- Rimosso messaggio di errore fuorviante quando link caricaAKN non disponibile
10+
- Sostituito con messaggio informativo: "⚠️ Link caricaAKN non trovato, tentativo con fallback..."
11+
- Aggiunti indicatori di progresso per download via OpenData:
12+
- Messaggio iniziale "🔄 Tentativo download via API OpenData..."
13+
- Indicatore animato "⏳ Preparazione collezione OpenData..." con puntini durante polling
14+
- Messaggio di successo "✅ File XML (OpenData) salvato in: ..."
15+
- Modificato quiet mode: messaggi di progresso visibili su stderr anche quando output va a stdout
16+
- Messaggi soppressi solo con flag --quiet esplicito
17+
- Fix UX: utente ora vede chiaramente che download è in corso, evita confusione su comando bloccato
18+
519
## 2026-01-12
620

721
### URL con escape backslash

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "normattiva2md"
7-
version = "2.1.8"
7+
version = "2.1.9"
88
description = "Convertitore da XML Akoma Ntoso a formato Markdown con download automatico delle leggi citate e cross-references inline (CLI: normattiva2md)"
99
readme = "README.md"
1010
requires-python = ">=3.7"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def read_readme():
1919

2020
setup(
2121
name="normattiva2md",
22-
version="2.1.8",
22+
version="2.1.9",
2323
description="Convertitore da XML Akoma Ntoso a formato Markdown con download automatico delle leggi citate e cross-references inline (CLI: normattiva2md)",
2424
long_description=read_readme(),
2525
long_description_content_type="text/markdown",

src/normattiva2md/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,9 @@ def main():
667667
params = None
668668
session = None
669669
if not args.opendata:
670+
# Show progress even when output goes to stdout (unless --quiet)
670671
params, session = extract_params_from_normattiva_url(
671-
input_source, quiet=quiet_mode
672+
input_source, quiet=args.quiet
672673
)
673674

674675
if not quiet_mode:
@@ -718,12 +719,13 @@ def main():
718719
),
719720
}
720721
else:
722+
# Show progress even when output goes to stdout (unless --quiet)
721723
success, metadata, session = download_akoma_ntoso_via_opendata(
722-
input_source, xml_temp_path, session=session, quiet=quiet_mode
724+
input_source, xml_temp_path, session=session, quiet=args.quiet
723725
)
724726
if not success:
725727
success, metadata, session = download_akoma_ntoso_via_export(
726-
input_source, xml_temp_path, session=session, quiet=quiet_mode
728+
input_source, xml_temp_path, session=session, quiet=args.quiet
727729
)
728730
if not success:
729731
print(

src/normattiva2md/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
MAX_FILE_SIZE_MB = 50
88
MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024
99
DEFAULT_TIMEOUT = 30
10-
VERSION = "2.1.8"
10+
VERSION = "2.1.9"

src/normattiva2md/normattiva_api.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,13 @@ def extract_params_from_normattiva_url(url, session=None, quiet=False):
195195
if all(k in params for k in ["dataGU", "codiceRedaz", "dataVigenza"]):
196196
return params, session
197197

198-
# Se il link caricaAKN non è presente, probabilmente l'XML non è disponibile
198+
# Se il link caricaAKN non è presente, ritorna None per tentare il fallback
199199
if not link_match:
200-
print(
201-
"❌ ERRORE: Normattiva non espone il link caricaAKN per questo atto.",
202-
file=sys.stderr,
203-
)
204-
print(
205-
" In questi casi l'esportazione XML sembra richiedere autenticazione",
206-
file=sys.stderr,
207-
)
208-
print(
209-
" o non essere disponibile per l'atto richiesto.",
210-
file=sys.stderr,
211-
)
200+
if not quiet:
201+
print(
202+
"⚠️ Link caricaAKN non trovato, tentativo con fallback...",
203+
file=sys.stderr,
204+
)
212205
return None, session
213206

214207
# Estrai parametri dagli input hidden usando regex (fallback)
@@ -447,6 +440,9 @@ def download_akoma_ntoso_via_opendata(url, output_path, session=None, quiet=Fals
447440
"Accept-Language": "it-IT,it;q=0.9,en;q=0.8",
448441
}
449442

443+
if not quiet:
444+
print("🔄 Tentativo download via API OpenData...", file=sys.stderr)
445+
450446
try:
451447
response = session.get(
452448
url, headers={**headers, "Accept": "text/html"}, timeout=DEFAULT_TIMEOUT
@@ -519,6 +515,10 @@ def download_akoma_ntoso_via_opendata(url, output_path, session=None, quiet=Fals
519515

520516
status_url = f"{base_url}/api/v1/ricerca-asincrona/check-status/{token}"
521517
stato = None
518+
519+
if not quiet:
520+
print("⏳ Preparazione collezione OpenData", end="", file=sys.stderr, flush=True)
521+
522522
for _ in range(60):
523523
try:
524524
status_response = session.get(
@@ -534,8 +534,14 @@ def download_akoma_ntoso_via_opendata(url, output_path, session=None, quiet=Fals
534534
break
535535
except requests.RequestException:
536536
pass
537+
538+
if not quiet:
539+
print(".", end="", file=sys.stderr, flush=True)
537540
time.sleep(2)
538541

542+
if not quiet:
543+
print() # New line after progress dots
544+
539545
if stato != 3:
540546
print("❌ ERRORE: ricerca OpenData non completata in tempo utile.", file=sys.stderr)
541547
return False, None, session

0 commit comments

Comments
 (0)