niming_backend/supaclient.py

29 lines
726 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):
2024-11-08 01:41:39 +08:00
if len(args) == 2 and args[0] == "newpost":
2024-11-07 17:33:34 +08:00
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