niming_backend/supaclient.py
pictures2333 ab47043281 logger
2024-11-07 17:33:34 +08:00

29 lines
707 B
Python

from supabase import Client, create_client
from dotenv import load_dotenv
import os
load_dotenv()
# service url
URL = os.getenv("SUPABASE_IP")
# service key
KEY = os.getenv("SUPABASE_KEY")
class supaClient:
def __init__(self):
self.client = create_client(URL, KEY)
# logger
def logger(dbclient: Client, args: list):
if args[0] == "newpost":
hash:str = args[1]
pres = dbclient.table("niming_posts").select("id, hash").eq("hash", hash).execute()
id = int(pres.data[0]["id"])
dbres = dbclient.table("niming_log").insert({
"message": "[id=%d] new post"%id,
"source": "client"
}).execute()
return dbres
return None