From 5aab418d0da611413551746deb2674c5d446814e Mon Sep 17 00:00:00 2001 From: Corma Martinez del Rio <66973815+cmdelrio@users.noreply.github.com> Date: Wed, 27 Sep 2023 08:26:34 -0600 Subject: [PATCH] Hopefully last linting issue --- parsons/mobilecommons/mobilecommons.py | 86 ++++++++++++++------------ 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/parsons/mobilecommons/mobilecommons.py b/parsons/mobilecommons/mobilecommons.py index 88d054ae50..4353468780 100644 --- a/parsons/mobilecommons/mobilecommons.py +++ b/parsons/mobilecommons/mobilecommons.py @@ -16,7 +16,15 @@ MC_URI = "https://secure.mcommons.com/api/" DATE_FMT = "%Y-%m-%d" -format_date = lambda x: parse_date(x).strftime(DATE_FMT) if x is not None else None + + +def _format_date(user_entered_date): + if user_entered_date: + formatted_date = parse_date(user_entered_date).strftime(DATE_FMT) + else: + formatted_date = None + return formatted_date + class MobileCommons: """ @@ -42,13 +50,13 @@ def __init__(self, username=None, password=None, company_id=None): self.client = APIConnector(uri=MC_URI, auth=(self.username, self.password)) def _mc_get_request( - self, - endpoint, - first_data_key, - second_data_key, - params, - elements_to_unpack=None, - limit=None, + self, + endpoint, + first_data_key, + second_data_key, + params, + elements_to_unpack=None, + limit=None, ): """ A function for GET requests that handles MobileCommons xml responses and pagination @@ -138,7 +146,7 @@ def _mc_get_request( page += 1 page_params = {"page": str(page), **params} logger.info( - f"Fetching rows {(page - 1) * page_limit + 1} - {(page)*page_limit} " + f"Fetching rows {(page - 1) * page_limit + 1} - {(page) * page_limit} " f"of {limit}" ) # Send get request @@ -224,7 +232,7 @@ def _mc_post_request(self, endpoint, params): raise HTTPError(response_dict["response"]["error"]) def get_broadcasts( - self, first_date=None, last_date=None, status=None, campaign_id=None, limit=None + self, first_date=None, last_date=None, status=None, campaign_id=None, limit=None ): """ A function for get broadcasts @@ -246,8 +254,8 @@ def get_broadcasts( """ params = { - "start_time": format_date(first_date), - "end_time": format_date(last_date), + "start_time": _format_date(first_date), + "end_time": _format_date(last_date), "campaign_id": campaign_id, "status": status, **self.default_params, @@ -263,12 +271,12 @@ def get_broadcasts( ) def get_campaign_subscribers( - self, - campaign_id: int, - first_date: str = None, - last_date: str = None, - opt_in_path_id: int = None, - limit: int = None, + self, + campaign_id: int, + first_date: str = None, + last_date: str = None, + opt_in_path_id: int = None, + limit: int = None, ): """ A function for getting subscribers of a specified campaign @@ -294,8 +302,8 @@ def get_campaign_subscribers( params = { "campaign_id": campaign_id, - "from": format_date(first_date), - "to": format_date(last_date), + "from": _format_date(first_date), + "to": _format_date(last_date), "opt_in_path_id": opt_in_path_id, **self.default_params, } @@ -309,13 +317,13 @@ def get_campaign_subscribers( ) def get_profiles( - self, - phones: list = None, - first_date: str = None, - last_date: str = None, - include_custom_columns: bool = False, - include_subscriptions: bool = False, - limit: int = None, + self, + phones: list = None, + first_date: str = None, + last_date: str = None, + include_custom_columns: bool = False, + include_subscriptions: bool = False, + limit: int = None, ): """ A function for getting profiles, which are MobileCommons people records @@ -346,8 +354,8 @@ def get_profiles( params = { "phone_number": phones, - "from": format_date(first_date), - "to": format_date(last_date), + "from": _format_date(first_date), + "to": _format_date(last_date), "include_custom_columns": custom_cols, "include_subscriptions": subscriptions, **self.default_params, @@ -363,16 +371,16 @@ def get_profiles( ) def create_profile( - self, - phone, - first_name=None, - last_name=None, - zip=None, - addressline1=None, - addressline2=None, - city=None, - state=None, - opt_in_path_id=None, + self, + phone, + first_name=None, + last_name=None, + zip=None, + addressline1=None, + addressline2=None, + city=None, + state=None, + opt_in_path_id=None, ): """ A function for creating a single MobileCommons profile