- MANUAL-PRODUTO.md: Manual do usuário final - MANUAL-VENDAS.md: Estratégia comercial e vendas - MANUAL-TECNICO.md: Infraestrutura e deploy - README.md: Visão geral do projeto
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
import httpx
|
|
from typing import Optional
|
|
|
|
async def fetch_product(barcode: str) -> Optional[dict]:
|
|
url = f"https://world.openfoodfacts.org/api/v2/product/{barcode}.json"
|
|
headers = {"User-Agent": "Aletheia/1.0 (contato@aletheia.app)"}
|
|
try:
|
|
async with httpx.AsyncClient(timeout=10) as client:
|
|
resp = await client.get(url, headers=headers)
|
|
if resp.status_code != 200:
|
|
return None
|
|
data = resp.json()
|
|
if data.get("status") != 1:
|
|
return None
|
|
p = data["product"]
|
|
return {
|
|
"name": p.get("product_name") or p.get("product_name_pt") or "Produto desconhecido",
|
|
"brand": p.get("brands", ""),
|
|
"category": p.get("categories", ""),
|
|
"ingredients_text": p.get("ingredients_text") or p.get("ingredients_text_pt") or "",
|
|
"nutri_score": (p.get("nutriscore_grade") or "").lower(),
|
|
"nova_group": p.get("nova_group"),
|
|
"nutrition": p.get("nutriments", {}),
|
|
"image_url": p.get("image_url", ""),
|
|
}
|
|
except Exception:
|
|
return None
|