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")