include exported at field

This commit is contained in:
Pablo Martin 2024-06-11 23:07:15 +02:00
parent 1a6260b90b
commit 4973d4c61a

View file

@ -1,4 +1,5 @@
import csv
import datetime
import pathlib
from abc import ABC, abstractmethod
@ -20,9 +21,11 @@ class CSVRateWriter(RateWriter):
def write_rates(self, rates: ExchangeRates) -> None:
with open(self.output_file_path, mode="w") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(["from_currency", "to_currency", "rate", "rate_date"])
csv_writer.writerow(
["from_currency", "to_currency", "rate", "rate_date", "exported_at"]
)
# Write the exchange rate data
exported_at = datetime.datetime.now()
for rate in rates._rate_index.values():
csv_writer.writerow(
[
@ -30,5 +33,6 @@ class CSVRateWriter(RateWriter):
rate.to_currency.value,
rate.rate.amount,
rate.rate_date.strftime("%Y-%m-%d"),
exported_at.isoformat(timespec="seconds"),
]
)