-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): add init script for camera, remove global variable as…
… database
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |