-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_knowledge.py
More file actions
executable file
·47 lines (39 loc) · 1.4 KB
/
Copy pathexport_knowledge.py
File metadata and controls
executable file
·47 lines (39 loc) · 1.4 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
#!/usr/bin/env python3
"""
Helper script to export all captured knowledge to JSON format
"""
import json
import sys
from datetime import datetime
from database import KnowledgeDB
def export_responses(output_file=None):
"""Export all responses to JSON"""
try:
db = KnowledgeDB()
responses = db.get_all_responses()
stats = db.get_stats()
# Create export data structure
export_data = {
'exported_at': datetime.now().isoformat(),
'statistics': stats,
'responses': responses
}
# Determine output filename
if not output_file:
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
output_file = f'knowledge_export_{timestamp}.json'
# Write to file
with open(output_file, 'w') as f:
json.dump(export_data, f, indent=2)
print(f"✓ Successfully exported {len(responses)} responses!")
print(f"✓ File saved to: {output_file}")
print(f"\nStatistics:")
print(f" Total Questions: {stats['total_questions']}")
print(f" Total Responses: {stats['total_responses']}")
print(f" Completion: {stats['completion_percentage']:.1f}%")
except Exception as e:
print(f"Error: {str(e)}")
sys.exit(1)
if __name__ == '__main__':
output_file = sys.argv[1] if len(sys.argv) > 1 else None
export_responses(output_file)