diff --git a/README.md b/README.md index 683aa97..44efc19 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,22 @@ To use `xexe`, you will need to have credentials for the `xe.com` API. Specifically, you need an account id and it's matching api key. +To write into the DWH, you will also need to pass credentials to connect it to it. + To set up your environment, you should create a `.env` file and place it in `~/.xexe/.env`. You will have to run `xexe` as the right user to ensure the `.env` file is found. You can use the `.env-example` file as a reference. We also recommend running `chmod 400` or `chmod 600` on it for safety. -Once you have done this, you can run `xexe xe-healthcheck`. If the connection to the API was successful, you will see some output telling you so. +Once you have done this, you can run: + +- `xexe xe-healthcheck` to validate the connection to the xe.com API. If the connection to the API was successful, you will see some output telling you so. +- `xexe dwh-healthcheck` to validate that the DWH is reachable. Again, you will see some happy output if things work. + +### DWH pre-requisites + +To be able to write rates into the DWH, take these points into consideration: + +- `xexe` expects to find the following: a database called `dwh`, schema called `sync_xedotcom_currencies`. These should already exist before `xexe` runs. +- `xexe` should run with a user that has permission to write into `dwh/sync_xedotcom_currencies` and to create tables. It will create the right tables if it can't find them. +- These details are hardcoded in the `constants` module. You might want to refactor them into run-time configuration options if you find yourself having to change them often. ### Using @@ -31,6 +44,12 @@ You can use `xexe` to get rates and store them locally like this: xexe get-rates --start-date "2024-01-01" --end-date "2024-01-10" --output my_rates.csv ``` +If you want to point writing to the DWH instead of a local file. + +```bash +xexe get-rates --output dwh +``` + You can also run without specifying dates. Not specifying `end-date` will get rates up to today. Not specifying `start-date` will get dates up to last week. ```bash diff --git a/xexe/cli.py b/xexe/cli.py index dbc973a..5403cb4 100644 --- a/xexe/cli.py +++ b/xexe/cli.py @@ -8,7 +8,7 @@ import click import pyfiglet from dotenv import load_dotenv -from xexe.constants import PATHS +from xexe.constants import PATHS, RATES_SOURCES from xexe.inputs_handling import handle_get_rates_inputs from xexe.processes import run_get_rates, run_xe_healthcheck @@ -66,6 +66,7 @@ def xe_healthcheck(): "--currencies", default=",".join([]), show_default=True, type=click.STRING ) @click.option("--dry-run", is_flag=True) +@click.option("--rates-source", type=click.Choice(RATES_SOURCES.keys()), default="mock") @click.option("--ignore-warnings", is_flag=True) @click.option("--output", type=click.STRING, required=True) def get_rates( @@ -73,6 +74,7 @@ def get_rates( end_date: Union[str, datetime.datetime, datetime.date], currencies: Union[None, str], dry_run: bool, + rates_sources: str, ignore_warnings: bool, output: pathlib.Path, ): @@ -81,6 +83,7 @@ def get_rates( end_date=end_date, currencies=currencies, dry_run=dry_run, + rates_sources=rates_sources, ignore_warnings=ignore_warnings, output=output, ) diff --git a/xexe/constants.py b/xexe/constants.py index 051b84b..7066779 100644 --- a/xexe/constants.py +++ b/xexe/constants.py @@ -3,8 +3,12 @@ from dataclasses import dataclass from money.currency import Currency +from xexe.rate_fetching import MockRateFetcher, XERateFetcher + DEFAULT_CURRENCIES = {Currency("EUR"), Currency("GBP"), Currency("USD")} +RATES_SOURCES = {"mock": MockRateFetcher, "xe": XERateFetcher} + @dataclass class PATHS: diff --git a/xexe/inputs_handling.py b/xexe/inputs_handling.py index 67e3fbb..cab72c2 100644 --- a/xexe/inputs_handling.py +++ b/xexe/inputs_handling.py @@ -5,7 +5,7 @@ from typing import Union from money.currency import Currency -from xexe.constants import DEFAULT_CURRENCIES +from xexe.constants import DEFAULT_CURRENCIES, RATES_SOURCES from xexe.utils import DateRange logger = logging.getLogger() @@ -16,6 +16,7 @@ def handle_get_rates_inputs( end_date: Union[datetime.datetime, datetime.date], currencies: Union[None, str], dry_run: bool, + rates_source: str, ignore_warnings: bool, output: Union[str, pathlib.Path], ): @@ -36,6 +37,9 @@ def handle_get_rates_inputs( logger.info("No currency list passed. Running for default currencies.") currencies = DEFAULT_CURRENCIES + if rates_source not in RATES_SOURCES: + raise ValueError(f"--rates-source must be one of {RATES_SOURCES.keys()}.") + # The Path constructor is idempotent, so this works equally fine if output # is a string or an actual Path object. output = pathlib.Path(output) @@ -46,6 +50,7 @@ def handle_get_rates_inputs( "date_range": date_range, "currencies": currencies, "dry_run": dry_run, + "rates_source": rates_source, "ignore_warnings": ignore_warnings, "output": output, }