40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import urllib.request
|
|
import json
|
|
import ssl
|
|
|
|
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_one_row(table):
|
|
try:
|
|
# Limit 1 to just see columns
|
|
url = f"{SUPA_URL}/rest/v1/{table}?select=*&limit=1"
|
|
req = urllib.request.Request(url, headers=headers)
|
|
context = ssl._create_unverified_context()
|
|
with urllib.request.urlopen(req, context=context, timeout=5) as response:
|
|
if response.status == 200:
|
|
data = json.loads(response.read().decode())
|
|
if len(data) > 0:
|
|
return data[0]
|
|
else:
|
|
return "Empty table"
|
|
return f"Error {response.status}"
|
|
except Exception as e:
|
|
return str(e)
|
|
|
|
print("Checking 'ml_products' table columns:")
|
|
prod = get_one_row("ml_products")
|
|
if isinstance(prod, dict):
|
|
print("Columns found:", list(prod.keys()))
|
|
print("Sample Price keys:", [k for k in prod.keys() if 'price' in k])
|
|
print("Sample Stock keys:", [k for k in prod.keys() if 'stock' in k])
|
|
print("Sample Sales keys:", [k for k in prod.keys() if 'sale' in k])
|
|
else:
|
|
print(prod)
|