niming_backend/supaclient.py
2024-11-08 01:41:39 +08:00

29 lines
726 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 len(args) == 2 and 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