35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import csv
|
|
import io
|
|
from typing import List
|
|
from .base import Formatter
|
|
from ..types import ReportRow
|
|
|
|
|
|
class CSVFormatter(Formatter):
|
|
"""Форматтер для экспорта в CSV."""
|
|
|
|
def __init__(self, **kwargs):
|
|
super().__init__()
|
|
|
|
def format(self, rows: List[ReportRow]) -> str:
|
|
output = io.StringIO()
|
|
writer = csv.writer(output, dialect="excel")
|
|
writer.writerow(["Project", "Version", "Issue ID", "Subject", "Status", "Spent Time"])
|
|
for r in rows:
|
|
writer.writerow(
|
|
[
|
|
r["project"],
|
|
r["version"],
|
|
r["issue_id"],
|
|
r["subject"],
|
|
r["status_ru"],
|
|
r["time_text"],
|
|
]
|
|
)
|
|
return output.getvalue()
|
|
|
|
def save(self, rows: List[ReportRow], output_path: str) -> None:
|
|
content = self.format(rows)
|
|
with open(output_path, "w", encoding="utf-8", newline="") as f:
|
|
f.write(content)
|