Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Utility functions for the project.
"""

import csv
import json

def export_to_csv(data, filename):
"""Export list of dicts to CSV file."""
if not data:
return
with open(filename, 'w', newline="") as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)

def export_to_json(data, filename):
"""Export data to JSON file."""
with open(filename, 'w') as f:
json.dump(data, f, indent=2)
Loading