data-xexe/xexe/processes.py
2024-06-11 13:52:31 +02:00

69 lines
1.9 KiB
Python

import logging
import os
import pathlib
from typing import List
from money.currency import Currency
from xecd_rates_client import XecdClient
from xexe.utils import DateRange
logger = logging.getLogger()
def run_xe_healthcheck() -> None:
"""
Try to request the account data in xe.com's API.
If certain fields about the account are returned, it means the request was
successful.
"""
logger.info("Creating client.")
xecd = XecdClient(
account_id=os.environ["XE_ACCOUNT_ID"],
api_key=os.environ["XE_API_KEY"],
)
logger.info("Requesting account info.")
try:
account_info_response = xecd.account_info()
except Exception as e:
logger.error(
"There was an exception when trying to reach xe.com. See details below."
)
logger.error(e)
raise e
contains_good_response_fields = bool(
("id" in account_info_response.keys())
and ("organization" in account_info_response.keys())
and ("package" in account_info_response.keys()),
)
if not contains_good_response_fields:
logger.error("Didn't find the fields of a good response.")
raise ConnectionError("Response from xe.com is not successful.")
logger.info("xe.com reached successfully.")
logger.info("See response below.")
logger.info(account_info_response)
def run_get_rates(
date_range: DateRange,
currencies: List[Currency],
dry_run: bool,
output: pathlib.Path,
) -> None:
logger.info("Getting rates")
# Create process log object to track everything
# Get rates
## Derive API calls to run from passed inputs
## Get hold of proper API client depending on whether we are dry running or acting serious
## Do our thing and get rates or die tryin'
# Output
## Create proper output writer depending on parameters
## Check writeability
## Do our thing and output or die tryin'
# Call it a day