in data-analytics/minigolf-demo/upload.py [0:0]
def monitor_and_upload(folder_path):
"""
Continuously monitors the Pixel folder for new video files and uploads them to GCS.
"""
if not os.path.isdir(folder_path):
print(f"Error: Invalid folder path '{folder_path}'.")
sys.exit(1) # Exit with an error code
# Keep track of existing files and their last modified times
existing_files = {
file_path.name: file_path.stat().st_mtime
for file_path in Path(folder_path).iterdir() if file_path.is_file()
}
while True:
latest_file = get_latest_file(folder_path)
if latest_file and latest_file.name not in existing_files:
file_path = str(latest_file.absolute())
file_size = 0
while file_size < os.path.getsize(file_path):
print("File is recording, waiting until recording is completed...")
file_size = os.path.getsize(file_path)
time.sleep(3)
print("recording is completed. Uploading...")
upload_file_to_gcs(file_path)
existing_files[latest_file.name] = latest_file.stat().st_mtime
else:
print("No new file detected. Monitoring...")
time.sleep(MONITORING_INTERVAL)