32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import urllib.request
|
|
import json
|
|
import ssl
|
|
import sys
|
|
import io
|
|
|
|
if sys.platform == 'win32':
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
|
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
|
|
|
ctx = ssl.create_default_context()
|
|
ctx.check_hostname = False
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
req = urllib.request.Request("https://drip-zone.online/api/products?all=true")
|
|
with urllib.request.urlopen(req, context=ctx, timeout=15) as res:
|
|
data = json.loads(res.read().decode('utf-8'))
|
|
products = data.get('products', [])
|
|
print(f"Total productos obtenidos: {len(products)}")
|
|
categories = {}
|
|
for p in products:
|
|
cat = p.get('category') or 'Sin categoría'
|
|
categories[cat] = categories.get(cat, 0) + 1
|
|
|
|
print("\nDistribución actual por categoría:")
|
|
for cat, count in categories.items():
|
|
print(f" - {cat}: {count} productos")
|
|
|
|
print("\nPrimeros 5 productos con nombre y categoría:")
|
|
for p in products[:5]:
|
|
print(f" * [{p.get('category')}] {p.get('name')} (Brand: {p.get('brand')})")
|