-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_document_status.py
More file actions
79 lines (62 loc) · 2.26 KB
/
check_document_status.py
File metadata and controls
79 lines (62 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""
Quick script to check document status in database
Usage:
python check_document_status.py # Show last 10 documents
python check_document_status.py <id> # Show specific document
"""
import sys
from db.db_manager import DatabaseManager
from config import config
db = DatabaseManager(config.DATABASE_PATH)
if len(sys.argv) > 1:
# Check specific document
try:
doc_id = int(sys.argv[1])
except ValueError:
print(f"Error: '{sys.argv[1]}' is not a valid document ID")
sys.exit(1)
doc_info = db.get_document_by_id(doc_id)
if not doc_info:
print(f"Document ID {doc_id} not found")
sys.exit(1)
print("=" * 80)
print(f"Document #{doc_id}")
print("=" * 80)
size_mb = doc_info.get('file_size_bytes', 0) / (1024 * 1024)
print(f"\nFilename: {doc_info.get('filename')}")
print(f"Path: {doc_info.get('relative_path')}")
print(f"Status: {doc_info.get('processing_status', 'unknown')}")
print(f"Size: {size_mb:.2f} MB")
print(f"OCR Processed: {doc_info.get('ocr_processed', False)}")
print(f"Progress: {doc_info.get('processing_progress', 0):.1f}%")
if doc_info.get('processing_error'):
print(f"Error/Reason: {doc_info['processing_error']}")
if doc_info.get('last_indexed_at'):
print(f"Last Indexed: {doc_info['last_indexed_at']}")
print("\n" + "=" * 80)
else:
# Get all documents sorted by ID
with db.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT id, filename, processing_status, file_size_bytes, processing_error
FROM pdf_documents
ORDER BY id DESC
LIMIT 10
""")
docs = cursor.fetchall()
print("=" * 80)
print("Recent documents in database:")
print("=" * 80)
for doc in docs:
size_mb = doc['file_size_bytes'] / (1024 * 1024) if doc['file_size_bytes'] else 0
status = doc['processing_status'] or 'unknown'
error = doc['processing_error'] or ''
print(f"\nID: {doc['id']}")
print(f" File: {doc['filename']}")
print(f" Status: {status}")
print(f" Size: {size_mb:.2f} MB")
if error:
print(f" Reason: {error}")
print("\n" + "=" * 80)