diff --git a/__pycache__/pdf_renamer.cpython-313.pyc b/__pycache__/pdf_renamer.cpython-313.pyc index 89c93b7..274461b 100644 Binary files a/__pycache__/pdf_renamer.cpython-313.pyc and b/__pycache__/pdf_renamer.cpython-313.pyc differ diff --git a/create_test_job.py b/create_test_job.py new file mode 100644 index 0000000..56b03a6 --- /dev/null +++ b/create_test_job.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +""" +Create a test processing job to verify progress updates +""" +import json +from pdf_renamer import job_queue, save_jobs + +# Create a test processing job +test_job = { + 'status': 'processing', + 'files': [{'name': 'test.pdf', 'path': '/tmp/test.pdf'}], + 'zip_path': None, + 'zip_name': None, + 'processed_files': [], + 'skipped': [], + 'created_at': '2025-11-07 10:00:00', + 'job_id': '2025-11-07_10-00-00', + 'progress': 'Test progress - should update every second' +} + +job_queue['2025-11-07_10-00-00'] = test_job +save_jobs() + +print('Created test processing job with progress updates') +print('Job ID: 2025-11-07_10-00-00') +print('Status: processing') +print('Progress: Test progress - should update every second') \ No newline at end of file diff --git a/jobs.json b/jobs.json index 85672fd..f3357df 100644 --- a/jobs.json +++ b/jobs.json @@ -1,6 +1,6 @@ { - "2024-01-01_12-00-00": { - "status": "completed", + "2025-11-07_10-00-00": { + "status": "processing", "files": [ { "name": "test.pdf", @@ -11,8 +11,8 @@ "zip_name": null, "processed_files": [], "skipped": [], - "created_at": "2024-01-01 12:00:00", - "job_id": "2024-01-01_12-00-00", - "progress": "Created ZIP archive with 1 organized files" + "created_at": "2025-11-07 10:00:00", + "job_id": "2025-11-07_10-00-00", + "progress": "Test progress - should update every second" } } \ No newline at end of file diff --git a/pdf_renamer.py b/pdf_renamer.py index c5bb8a9..8c4b644 100644 --- a/pdf_renamer.py +++ b/pdf_renamer.py @@ -511,7 +511,6 @@ def process_job(job_id, files): job_queue[job_id]['status'] = 'processing' job_queue[job_id]['progress'] = 'Starting job processing...' save_jobs() # Persist initial progress - save_jobs() # Persist status change processed_files = [] temp_extract_dirs = [] @@ -561,6 +560,7 @@ def process_job(job_id, files): print(f"DEBUG: ZIP contains {file_count} files: {zip_ref.namelist()}") zip_ref.extractall(extract_dir) job_queue[job_id]['progress'] = f'Extracted {file_count} files from {filename}' + save_jobs() # Persist ZIP extraction progress print(f"DEBUG: ZIP extraction completed, progress updated: {job_queue[job_id]['progress']}") # Process PDFs in extract_dir @@ -571,6 +571,7 @@ def process_job(job_id, files): pdf_files_found.append(f) pdf_path = os.path.join(root, f) job_queue[job_id]['progress'] = f'Processing PDF: {f}' + save_jobs() # Persist current file progress print(f"DEBUG: Processing PDF: {f} at {pdf_path}") print(f"DEBUG: File exists: {os.path.exists(pdf_path)}") pdf_info = extract_names_from_pdf(pdf_path) @@ -604,6 +605,7 @@ def process_job(job_id, files): processed_files.append(('success', os.path.relpath(new_path, episode_dir), new_path)) processed_count += 1 job_queue[job_id]['progress'] = f'Organized {processed_count}/{total_files} files' + save_jobs() # Persist progress update print(f"DEBUG: Organized file {processed_count}/{total_files}") print(f"DEBUG: Found {len(pdf_files_found)} PDF files in ZIP: {pdf_files_found}") @@ -617,6 +619,7 @@ def process_job(job_id, files): # Single PDF try: job_queue[job_id]['progress'] = f'Processing PDF: {filename}' + save_jobs() # Persist current file progress pdf_info = extract_names_from_pdf(filepath) if 'error' in pdf_info: processed_files.append(('skipped', filename, pdf_info['error'])) @@ -640,6 +643,7 @@ def process_job(job_id, files): processed_files.append(('success', os.path.relpath(new_filepath, episode_dir), new_filepath)) processed_count += 1 job_queue[job_id]['progress'] = f'Organized {processed_count}/{total_files} files' + save_jobs() # Persist progress update except Exception as e: processed_files.append(('skipped', filename, f'PDF processing error: {str(e)}')) job_queue[job_id]['progress'] = f'Failed to process PDF {filename}: {str(e)}' @@ -1034,6 +1038,21 @@ def jobs(): // Track previous job statuses to detect completion let previousJobStatuses = {}; + // Collapsible section functions + function toggleZipDetails(element) { + const details = element.nextElementSibling; + const isVisible = details.style.display === 'block'; + details.style.display = isVisible ? 'none' : 'block'; + element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼'); + } + + function toggleSkippedDetails(element) { + const details = element.nextElementSibling; + const isVisible = details.style.display === 'block'; + details.style.display = isVisible ? 'none' : 'block'; + element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼'); + } + function updateJobs() { fetch('/api/jobs', { credentials: 'same-origin' }) .then(response => response.json()) @@ -1081,9 +1100,9 @@ def jobs(): }); // Add updated job elements - const jobs = Object.entries(data); - if (jobs.length > 0) { - jobs.forEach(([jobId, job]) => { + const jobEntries = Object.entries(data); + if (jobEntries.length > 0) { + jobEntries.forEach(([jobId, job]) => { const jobDiv = document.createElement('div'); jobDiv.className = 'job'; jobDiv.innerHTML = ` @@ -1149,21 +1168,6 @@ def jobs(): // Initialize previous job statuses updateJobs(); // Run once immediately to populate initial statuses - - // Collapsible section functions - function toggleZipDetails(element) { - const details = element.nextElementSibling; - const isVisible = details.style.display === 'block'; - details.style.display = isVisible ? 'none' : 'block'; - element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼'); - } - - function toggleSkippedDetails(element) { - const details = element.nextElementSibling; - const isVisible = details.style.display === 'block'; - details.style.display = isVisible ? 'none' : 'block'; - element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼'); - } diff --git a/simulate_progress.py b/simulate_progress.py new file mode 100644 index 0000000..58b21d0 --- /dev/null +++ b/simulate_progress.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +""" +Simulate progress updates for testing +""" +import time +import json +from pdf_renamer import job_queue, load_jobs, save_jobs + +# Load jobs +load_jobs() + +job_id = '2025-11-07_10-00-00' +if job_id in job_queue: + progress_messages = [ + 'Starting job processing...', + 'Found 3 files to process', + 'Processing PDF: document1.pdf', + 'Extracted data for John Doe', + 'Processing PDF: document2.pdf', + 'Extracted data for Jane Smith', + 'Processing PDF: document3.pdf', + 'Extracted data for Bob Johnson', + 'Organized 1/3 files', + 'Organized 2/3 files', + 'Organized 3/3 files', + 'Creating ZIP archive...', + 'Created ZIP archive with 3 organized files' + ] + + print(f'Starting progress simulation for job {job_id}') + for i, progress in enumerate(progress_messages): + job_queue[job_id]['progress'] = progress + save_jobs() + print(f'Updated progress: {progress}') + if i < len(progress_messages) - 1: # Don't sleep after last message + time.sleep(2) + + print('Progress simulation complete!') +else: + print(f'Job {job_id} not found') \ No newline at end of file diff --git a/test_progress_updates.py b/test_progress_updates.py new file mode 100644 index 0000000..1fefa6e --- /dev/null +++ b/test_progress_updates.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +""" +Test script to verify progress updates are working +""" +import json +from pdf_renamer import job_queue, load_jobs, save_jobs + +# Load current jobs +load_jobs() +print('Current jobs:') +for job_id, job in job_queue.items(): + status = job.get('status', 'unknown') + progress = job.get('progress', 'none') + print(f' {job_id}: status={status}, progress="{progress}"') + +# Test updating progress +if job_queue: + test_job_id = list(job_queue.keys())[0] + print(f'\nTesting progress update for job {test_job_id}') + + # Update progress + job_queue[test_job_id]['progress'] = 'Test progress update - ' + str(len(job_queue)) + save_jobs() + + # Reload and check + job_queue.clear() + load_jobs() + + updated_progress = job_queue.get(test_job_id, {}).get('progress', 'not found') + print(f'Updated progress: "{updated_progress}"') + + if 'Test progress update' in updated_progress: + print('✅ Progress updates are working!') + else: + print('❌ Progress updates not working') +else: + print('No jobs found to test with') \ No newline at end of file