added image upload to database test

This commit is contained in:
Brian Bjarke Jensen
2024-02-20 19:58:03 +01:00
parent e5a09a791d
commit d3ecc50075
4 changed files with 26 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

+26
View File
@@ -0,0 +1,26 @@
from pathlib import Path
from dotenv import load_dotenv
from pymongo import MongoClient
import os
from src.database import VisualCommunication, connect
if __name__ == "__main__":
# get list of image paths
test_dir = Path(__file__).parent
img_dir = test_dir / "imgs"
img_path_list = [path for path in img_dir.glob("*.jpeg") if path.is_file()]
print(img_path_list)
# instantiate data object
vis_com_list = [VisualCommunication.from_file(path) for path in img_path_list]
for vis_com in vis_com_list:
print(repr(vis_com))
# upload images to database
env_path = test_dir.parent / "mongodb.env"
assert env_path.exists()
load_dotenv(env_path)
collection, db, client = connect()
print(client.server_info())
for vis_com in vis_com_list:
result = collection.insert_one(vis_com.model_dump_json())
print(f"inserted document: {result}")