MPR 'Py Script: Get video in bucket and insert into DB'

Reviewed-on: #26
This commit is contained in:
Matúš Juraj Kobyľan 2024-11-24 20:38:31 +00:00
commit 25e0b9a0c8

34
storage_to_db.py Normal file
View 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)