Skip to content

Commit

Permalink
feat(database): add init script for camera, remove global variable as…
Browse files Browse the repository at this point in the history
… database
  • Loading branch information
qmi03 committed May 16, 2024
1 parent 4fdd070 commit 8b8b0cf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/database/scripts/init_camera_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from datetime import datetime

from dotenv import load_dotenv
from pymongo import MongoClient

load_dotenv()
connection_string = f"mongodb://{os.environ.get('MONGO_USER')}:{os.environ.get('MONGO_PASSWORD')}@localhost:27017/"

camera_streams_data = [
{"id": 0, "stream_link": 0},
{"id": 1, "stream_link": "http://192.168.1.36:8080/video"},
# Add more camera streams as needed
]

if __name__ == "__main__":
mongo_client = MongoClient(connection_string)
iot_db = mongo_client.iot_232
camera_collection = iot_db["camera"]

if camera_collection.count_documents({}) > 0:
print("Data already exists in the collection. Exiting...")
else:
for data in camera_streams_data:
camera_collection.insert_one(data)

0 comments on commit 8b8b0cf

Please sign in to comment.