tests passing
This commit is contained in:
parent
de8828a9cb
commit
515a4527af
4 changed files with 79 additions and 69 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import csv
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
from abc import ABC, abstractmethod
|
||||
|
|
@ -10,6 +11,8 @@ from psycopg2 import sql
|
|||
from xexe.constants import DWH_SCHEMA, DWH_TABLE
|
||||
from xexe.exchange_rates import ExchangeRates
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class RateWriter(ABC):
|
||||
@abstractmethod
|
||||
|
|
@ -130,3 +133,18 @@ class DWHRateWriter(RateWriter):
|
|||
finally:
|
||||
cursor.close()
|
||||
self.connection.autocommit = True # Reset autocommit to its default state
|
||||
|
||||
|
||||
def build_rate_writer(output: str) -> RateWriter:
|
||||
output_is_csv_file_path = bool(pathlib.Path(output).suffix == ".csv")
|
||||
|
||||
if output_is_csv_file_path:
|
||||
logger.info("Creating CSV Rate Writer.")
|
||||
return CSVRateWriter(output_file_path=output)
|
||||
|
||||
output_is_dwh = bool(output == "dwh")
|
||||
if output_is_dwh:
|
||||
logger.info("Creating DWH Rate Writer.")
|
||||
return DWHRateWriter()
|
||||
|
||||
raise ValueError(f"Don't know how to handle passed output: {output}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue