WIP, looping through all of a user's cameras, creating folder structure for downloads

database
Mark Cotton 2023-09-19 22:17:14 -05:00
parent fdd0b2575c
commit 438d3bd751
1 changed files with 45 additions and 26 deletions

View File

@ -20,17 +20,29 @@ con = sqlite3.connect('instance/project.db')
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]]
print(pool.map(download, args, 1))
pool.map(download, args, 1)
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]
start = datetime.fromisoformat(start)
os.makedirs(f"videos/{camera_device_id}/{start.year}/{start.month}/{start.day}/", exist_ok=True)
save_result = args[2].save_video_to_file(url=row[1], filename=fname)
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']:
case 200:
@ -56,7 +68,7 @@ def download(args):
if __name__ == '__main__':
pool = Pool(16)
pool = Pool(64)
print("starting up...")
@ -96,32 +108,39 @@ if __name__ == '__main__':
een.get_list_of_cameras()
r2d2 = een.cameras[3]
# r2d2.get_list_of_videos(start_timestamp=een.time_before(hours=24*1), end_timestamp=een.time_now())
sql = '''SELECT
download.id,
download.url,
camera.device_id,
download.start_timestamp,
download.end_timestamp,
download.status
FROM
camera
JOIN download ON download.camera_id = camera.id
JOIN USER ON camera.user_id = user.id
WHERE
download.status == ?
AND camera.id == ?
LIMIT 2000;'''
# 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)
results = cur.execute(sql, ('new', 4))
# r2d2.get_list_of_videos(start_timestamp=een.time_before(hours=24*1), end_timestamp=een.time_now())
sql = '''SELECT
download.id,
download.url,
camera.device_id,
download.start_timestamp,
download.end_timestamp,
download.status
FROM
camera
JOIN download ON download.camera_id = camera.id
JOIN USER ON camera.user_id = user.id
WHERE
download.status == ?
AND camera.device_id == ?
ORDER BY download.start_timestamp
LIMIT 10000;'''
run([results, een, r2d2])
results = cur.execute(sql, ('new', current_camera.id))
run([results, een, current_camera])