Files
medical-mall/check_products.py

63 lines
2.2 KiB
Python

import urllib.request
import json
import ssl
# Config from ak/config.uts
SUPA_URL = 'http://192.168.1.61:18000'
SUPA_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlzcyI6InN1cGFiYXNlLTEiLCJpYXQiOjE3Njk2NzY0OTgsImV4cCI6MTkyNzM1NjQ5OH0.ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
headers = {
"apikey": SUPA_KEY,
"Authorization": f"Bearer {SUPA_KEY}",
"Content-Type": "application/json"
}
def get_data(table, query="select=*"):
try:
url = f"{SUPA_URL}/rest/v1/{table}?{query}"
print(f"Requesting: {url}")
req = urllib.request.Request(url, headers=headers)
context = ssl._create_unverified_context()
try:
with urllib.request.urlopen(req, context=context, timeout=5) as response:
if response.status == 200:
return json.loads(response.read().decode())
else:
return f"Error: {response.status}"
except urllib.error.URLError as e:
return f"Connection Failed: {e}"
except Exception as e:
return f"Exception: {e}"
merchant_id = "91a7129c-648e-47c7-91de-05f7268ed483"
print("--- DIAGNOSTIC START ---")
print(f"Checking products for merchant_id: {merchant_id}")
# Check ml_products
print("\n[ Checking ml_products ]")
products = get_data("ml_products", f"merchant_id=eq.{merchant_id}")
if isinstance(products, list):
print(f"Found {len(products)} products in ml_products table.")
if len(products) > 0:
print("Sample product:", products[0]['name'])
else:
print(f"Failed to fetch products: {products}")
# Check ml_products_detail_view
print("\n[ Checking ml_products_detail_view ]")
products_view = get_data("ml_products_detail_view", f"merchant_id=eq.{merchant_id}")
if isinstance(products_view, list):
print(f"Found {len(products_view)} products in view.")
else:
print(f"Failed to fetch products view: {products_view}")
# List all products just in case to see what merchant_ids exist
print("\n[ Listing first 5 products to check merchant_ids ]")
all_prod = get_data("ml_products", "limit=5&select=id,name,merchant_id")
if isinstance(all_prod, list):
for p in all_prod:
print(f" - {p.get('name')}: {p.get('merchant_id')}")
print("\n--- DIAGNOSTIC END ---")