consumer模块完成90%,完善店铺商品优惠券领取
This commit is contained in:
57
check_db_coupons.py
Normal file
57
check_db_coupons.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import urllib.request
|
||||
import json
|
||||
import ssl
|
||||
import time
|
||||
|
||||
# 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}"
|
||||
req = urllib.request.Request(url, headers=headers)
|
||||
# Ignore SSL errors for local IP
|
||||
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}"
|
||||
|
||||
print("--- DIAGNOSTIC START ---")
|
||||
print(f"Target: {SUPA_URL}")
|
||||
|
||||
# Check 1: Shops
|
||||
print("\n[ Checking Shops (ml_shops) ]")
|
||||
shops = get_data("ml_shops", "select=id,merchant_id,shop_name&status=eq.1")
|
||||
if isinstance(shops, list):
|
||||
print(f"Found {len(shops)} active shops.")
|
||||
for shop in shops:
|
||||
print(f" - {shop.get('shop_name')} (ID: {shop.get('merchant_id')})")
|
||||
else:
|
||||
print(f"Failed to fetch shops: {shops}")
|
||||
|
||||
# Check 2: Coupons
|
||||
print("\n[ Checking Coupons (ml_coupon_templates) ]")
|
||||
coupons = get_data("ml_coupon_templates", "select=id,name,merchant_id,status")
|
||||
if isinstance(coupons, list):
|
||||
print(f"Found {len(coupons)} coupon templates.")
|
||||
for coupon in coupons:
|
||||
mid_disp = coupon.get('merchant_id') if coupon.get('merchant_id') else "PLATFORM"
|
||||
print(f" - {coupon.get('name')} | Owner: {mid_disp} | Status: {coupon.get('status')}")
|
||||
else:
|
||||
print(f"Failed to fetch coupons: {coupons}")
|
||||
|
||||
print("\n--- DIAGNOSTIC END ---")
|
||||
Reference in New Issue
Block a user