Skip to content

Commit

Permalink
feat: add save_csv function
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiblett committed Nov 5, 2024
1 parent e021d02 commit 837c4bb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions serps/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import os
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -25,6 +26,15 @@ def save_excel(file_path: Path | str, data: DataFrame) -> None:
data.to_excel(writer)


def save_csv(output_dir: Path, output: list[dict]) -> None:
if len(output) == 0:
print(f"Failed to save {output_dir}. Output empty.")
return
with open(output_dir, "w") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=output[0].keys())
writer.writeheader()
writer.writerows(output)

def load_list(file_path: Path | str) -> dict[str, Any] | None:
if not file_path:
return
Expand Down

0 comments on commit 837c4bb

Please sign in to comment.