niming_backend/supaclient.py

29 lines
707 B
Python
Raw Normal View History

2024-11-07 02:19:53 +08:00
from supabase import Client, create_client
from dotenv import load_dotenv
import os
load_dotenv()
2024-11-07 17:33:34 +08:00
# service url
2024-11-07 02:19:53 +08:00
URL = os.getenv("SUPABASE_IP")
# service key
KEY = os.getenv("SUPABASE_KEY")
class supaClient:
def __init__(self):
2024-11-07 17:33:34 +08:00
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