data-xexe/xexe/processes.py

49 lines
1.3 KiB
Python
Raw Normal View History

2024-06-06 11:50:01 +02:00
import logging
2024-06-06 12:56:36 +02:00
import os
from xecd_rates_client import XecdClient
2024-06-06 11:50:01 +02:00
logger = logging.getLogger()
2024-06-06 12:58:15 +02:00
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.
"""
2024-06-06 12:56:36 +02:00
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:
2024-06-06 12:58:15 +02:00
logger.error("Didn't find the fields of a good response.")
2024-06-06 12:56:36 +02:00
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)
2024-06-06 17:39:20 +02:00
def run_get_rates():
logger.info("Getting rates")