Py Script: Get video in bucket and insert into DB #26
34
storage_to_db.py
Normal file
34
storage_to_db.py
Normal file
@ -0,0 +1,34 @@
|
||||
from supabase import create_client, Client
|
||||
|
||||
# RLS policy permissions required:
|
||||
# buckets table permissions: select
|
||||
# objects table permissions: none
|
||||
|
||||
url: str = ""
|
||||
key: str = ""
|
||||
supabase: Client = create_client(url, key)
|
||||
|
||||
|
||||
# List all objects in the 'video' bucket
|
||||
# .from("bucket_name")
|
||||
# .list("folder_name")
|
||||
response = supabase.storage.from_("video").list("",{"limit": 1000})
|
||||
|
||||
|
||||
for video in response:
|
||||
video_name = video['name'].replace('.mp4', '')
|
||||
video_url = f"{url}/storage/v1/object/public/video/{video_name}.mp4"
|
||||
|
||||
# print the video name and url with tabs
|
||||
print(video_name, video_url, sep="\t")
|
||||
|
||||
response = (
|
||||
# .table("table_name")
|
||||
# .insert({"column_name": value})
|
||||
# .execute SQL query
|
||||
supabase.table("Videa")
|
||||
.insert({"label": video_name, "video_url": video_url})
|
||||
.execute()
|
||||
)
|
||||
# print(response)
|
||||
|
Loading…
Reference in New Issue
Block a user