File size: 601 Bytes
490ec84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# export_to_spreadsheet.py

import csv
import os

def export_to_csv(data):
    if not data:
        print("No data to export. Skipping CSV creation.")
        return

    output_file = os.path.join(os.path.dirname(__file__), "digs_results.csv")

    try:
        with open(output_file, mode='w', newline='', encoding='utf-8') as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=data[0].keys())
            writer.writeheader()
            writer.writerows(data)
        print(f"CSV export successful: {output_file}")
    except Exception as e:
        print(f"Error writing CSV: {e}")