Skip to content
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e155871
Review- Removing unused imports
Ihebdhouibi Sep 15, 2024
8e43594
Review- Adding windows timeout mechanism
Ihebdhouibi Sep 15, 2024
04bb477
Review- removing obselete code
Ihebdhouibi Sep 15, 2024
694330d
Review- Encapsulate global variable in a config class
Ihebdhouibi Sep 15, 2024
48a7ecf
Review- fixing typo in ScraperConfig class
Ihebdhouibi Sep 15, 2024
9d03605
Review- fixing typo in timeout cnstr
Ihebdhouibi Sep 15, 2024
31fdb56
Review- Fixing search_download call
Ihebdhouibi Sep 15, 2024
34e6cad
Review- missing parentheses
Ihebdhouibi Sep 15, 2024
173afd2
Review- fixing typo
Ihebdhouibi Sep 15, 2024
2c863d7
Review- search_download call fix
Ihebdhouibi Sep 15, 2024
d948deb
Review- Establishing DB connection using context manager
Ihebdhouibi Sep 15, 2024
704250c
Review- Removing commented lines
Ihebdhouibi Sep 15, 2024
b58e70d
Review- Apply code reusebility to store alerts functions
Ihebdhouibi Sep 15, 2024
f7e3782
Review- Apply code reusebility to retrieving alerts functions
Ihebdhouibi Sep 15, 2024
042b951
Review- Add exception handling
Ihebdhouibi Sep 15, 2024
6289aa9
Review- Add remove_camera function
Ihebdhouibi Sep 15, 2024
5a17c59
Review- Fixing typo
Ihebdhouibi Sep 15, 2024
d628218
Review- Add exception handling
Ihebdhouibi Sep 15, 2024
caebad0
Review- Fixing typo and naming in functions
Ihebdhouibi Sep 15, 2024
8517949
Review- Updating create_azure_container function
Ihebdhouibi Sep 15, 2024
4075fc5
Review- Remove commented lines
Ihebdhouibi Sep 15, 2024
f7893a4
Review- Updating upload_blob function
Ihebdhouibi Sep 15, 2024
244dcb2
Review- removing debbuging and unecessary lines
Ihebdhouibi Sep 15, 2024
aae9185
Review- Removing unecessary prints
Ihebdhouibi Sep 16, 2024
f1e5c12
Review- Removing commented code
Ihebdhouibi Sep 16, 2024
39616c3
Review- Documenting functions
Ihebdhouibi Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions cloudStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime

import cv2
import numpy as np
import tempfile
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__


Expand Down Expand Up @@ -30,35 +30,34 @@ def create_azure_container(container_name = "alerts"):
except Exception as e:
print(f"Error creating container {container_name}: {e}")

def upload_blob(videoArray, videoName, width, height, fps):
def upload_blob(video_array, video_name, width, height, fps):

blob_service_client = init_blob_client()
current_time = datetime.now()
current_day = datetime.today()
current_time = current_time.strftime("%H:%M:%S")
videoName = videoName + " " + str(current_day) + " "+ current_time + ".mp4"
blob_client = blob_service_client.get_blob_client(container="alerts", blob=videoName)
current_time = datetime.now().strftime("%H:%M:%S")
current_day = datetime.today().strftime("%Y-%m-%d")

video_name = f"{video_name} {current_day} {current_time}.mp4"
blob_client = blob_service_client.get_blob_client(container="alerts", blob=video_name)
Comment on lines -36 to +40

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better code here


# Converting videoArray ( numpy array ) into video
# fps = 30 # 25 frames per second


# print(videoName)
output = cv2.VideoWriter(videoName, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height), True)
for i in videoArray:
output.write(i)
output.release()

path = "./" + videoName
# print("path : ", path)
with open(path, "rb") as data :
# Uploading video to the cloud
blob_client.upload_blob(data)
# Delete file after upload

os.remove(path)
try:
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_video_file:
output = cv2.VideoWriter(temp_video_file.name, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height), True)
for i in video_array:
output.write(i)
output.release()

with open(temp_video_file.name, "rb") as data:
# Uploading video to the cloud
blob_client.upload_blob(data)

os.remove(temp_video_file.name) # removing temporary file after upload
return blob_client.url

except Exception as e:
print(f"Error uploading video {video_name}: {e}")
return None
Comment on lines -42 to +58

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using tempfile here is better than hardcoding paths to avoid cross-platform or directory not writable issues


return blob_client.url