WIP, looping through all of a user's cameras, creating folder structure for downloads
parent
fdd0b2575c
commit
438d3bd751
|
@ -20,17 +20,29 @@ con = sqlite3.connect('instance/project.db')
|
||||||
|
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
|
# iterate through the first argument, appending the second and third to each iteration
|
||||||
args = [([i], args[1], args[2]) for i in args[0]]
|
args = [([i], args[1], args[2]) for i in args[0]]
|
||||||
print(pool.map(download, args, 1))
|
pool.map(download, args, 1)
|
||||||
|
|
||||||
|
|
||||||
def download(args):
|
def download(args):
|
||||||
|
|
||||||
row = args[0][0]
|
# explode arguments into variable names
|
||||||
|
row, een_obj, cam = args
|
||||||
|
|
||||||
fname = f"videos/{row[2]}/{row[2]}_{row[3]}-{row[4]}.mp4"
|
row = row[0]
|
||||||
|
camera_device_id = row[2]
|
||||||
|
start = row[3]
|
||||||
|
end = row[4]
|
||||||
|
|
||||||
save_result = args[2].save_video_to_file(url=row[1], filename=fname)
|
start = datetime.fromisoformat(start)
|
||||||
|
os.makedirs(f"videos/{camera_device_id}/{start.year}/{start.month}/{start.day}/", exist_ok=True)
|
||||||
|
|
||||||
|
fname = f"videos/{camera_device_id}/{start.year}/{start.month}/{start.day}/{camera_device_id}_{start}-{end}.mp4"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
save_result = cam.save_video_to_file(url=row[1], filename=fname)
|
||||||
|
|
||||||
match save_result['response_http_status']:
|
match save_result['response_http_status']:
|
||||||
case 200:
|
case 200:
|
||||||
|
@ -56,7 +68,7 @@ def download(args):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
pool = Pool(16)
|
pool = Pool(64)
|
||||||
print("starting up...")
|
print("starting up...")
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,7 +108,13 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
een.get_list_of_cameras()
|
een.get_list_of_cameras()
|
||||||
|
|
||||||
r2d2 = een.cameras[3]
|
|
||||||
|
# iterate through all the cameras this user has access to
|
||||||
|
for current_camera in een.cameras:
|
||||||
|
|
||||||
|
# create directories if they don't already exists
|
||||||
|
os.makedirs(f"videos/{current_camera.id}/", exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
# r2d2.get_list_of_videos(start_timestamp=een.time_before(hours=24*1), end_timestamp=een.time_now())
|
# r2d2.get_list_of_videos(start_timestamp=een.time_before(hours=24*1), end_timestamp=een.time_now())
|
||||||
|
|
||||||
|
@ -113,15 +131,16 @@ if __name__ == '__main__':
|
||||||
JOIN USER ON camera.user_id = user.id
|
JOIN USER ON camera.user_id = user.id
|
||||||
WHERE
|
WHERE
|
||||||
download.status == ?
|
download.status == ?
|
||||||
AND camera.id == ?
|
AND camera.device_id == ?
|
||||||
LIMIT 2000;'''
|
ORDER BY download.start_timestamp
|
||||||
|
LIMIT 10000;'''
|
||||||
|
|
||||||
|
|
||||||
results = cur.execute(sql, ('new', 4))
|
results = cur.execute(sql, ('new', current_camera.id))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
run([results, een, r2d2])
|
run([results, een, current_camera])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue