diff --git a/README.rst b/README.rst index 1dcab37..bf345bd 100644 --- a/README.rst +++ b/README.rst @@ -23,4 +23,5 @@ python setup.py test Changelog ----------------------------- +v0.0.26 - added TwoThirdBlast email type v0.0.23 - added HalfBlast email type \ No newline at end of file diff --git a/dive_sailthru_client/client.py b/dive_sailthru_client/client.py index 7d92653..820b82e 100644 --- a/dive_sailthru_client/client.py +++ b/dive_sailthru_client/client.py @@ -18,6 +18,7 @@ class DiveEmailTypes: Provides standard email types we use. """ Blast = "blast" + TwoThirdBlast = "twothirdblast" HalfBlast = "halfblast" ThirdBlast = "thirdblast" QuarterBlast = "quarterblast" @@ -92,6 +93,9 @@ def _infer_dive_email_type(self, campaign): # noqa: C901 - yeah it's complicat elif "Blast" in labels or '-blast-' in name or "blast=" in name or "blast list" in list_name.lower(): if "QuarterBlast" in name or "Quarters Blast List" in list_name or "Quarter Blast List" in list_name: return DiveEmailTypes.QuarterBlast + elif "twothirdblast" in name or "two thirds blast list" in list_name.lower() or "two third blast list" in list_name.lower(): + # Must go before standard third blast + return DiveEmailTypes.TwoThirdBlast elif "ThirdBlast" in name or "Thirds Blast List" in list_name or "Third Blast List" in list_name: return DiveEmailTypes.ThirdBlast elif "HalfBlast" in name or "Half Blast List" in list_name \ @@ -116,7 +120,7 @@ def _infer_dive_publication(self, campaign): """ # This function requires a dive_email_type, so if 'dive_email_type' is already a key - # in the campaign than use it, otherwise call it here. + # in the campaign then use it, otherwise call it here. if 'dive_email_type' in list(campaign.keys()): dive_email_type = campaign['dive_email_type'] else: @@ -129,8 +133,9 @@ def _infer_dive_publication(self, campaign): # blast list: "Utility Dive and sub pubs Blast List" # This regex handles that as well as normal blast lists return re.sub(r'( and sub pubs)? [Bb]last [Ll]ist$', '', list_name) - if dive_email_type in (DiveEmailTypes.HalfBlast, DiveEmailTypes.QuarterBlast, DiveEmailTypes.ThirdBlast) and "Group" in list_name: - return re.sub(r'( (Half|Thirds?|Quarters?))? Blast List - Group [A-D]$', '', list_name, flags=re.I) + if (dive_email_type in (DiveEmailTypes.HalfBlast, DiveEmailTypes.QuarterBlast, DiveEmailTypes.ThirdBlast, DiveEmailTypes.TwoThirdBlast) and + "Group" in list_name): + return re.sub(r'( (Half|(TWO )?Thirds?|Quarters?))? Blast List - Group [A-D]$', '', list_name, flags=re.I) if dive_email_type == DiveEmailTypes.Weekender and list_name.lower().endswith("weekender"): return re.sub(r' [Ww]eekender$', '', list_name) if dive_email_type == DiveEmailTypes.Newsletter: diff --git a/dive_sailthru_client/tests/test_diveSailthruClient.py b/dive_sailthru_client/tests/test_diveSailthruClient.py index 76dc740..8bc2686 100644 --- a/dive_sailthru_client/tests/test_diveSailthruClient.py +++ b/dive_sailthru_client/tests/test_diveSailthruClient.py @@ -236,6 +236,45 @@ def test_infer_dive_email_type_and_brand_real_examples(self): 'expected_type': DiveEmailTypes.QuarterBlast, 'comment': 'Marketing Dive Quarter Blast with param-type blast name', }, + { + 'input': { + 'blast_id' : 35893250, + 'email_count': 57400, + 'labels' : ['Blast'], + 'list' : 'Healthcare Dive TWO Third Blast List - Group B', + 'mode': 'email', + 'modify_time' : 'Mon, 01 Jul 2024 10:20:29 -0400', + 'modify_user' : 'xxx@industrydive.com', + 'name': 'client_name=CorroHealth&pt_id=a12PE000000L2bnYAC&blast=twothirdblast&site=HealthcareDive&send_date=07.09.2024', + 'from_name' : 'Healthcare Dive', + 'status' : 'created', + 'subject' : 'Boost Hospital Revenue 7X with AI', + 'suppress_list' : [], + }, + 'expected_publication': 'Healthcare Dive', + 'expected_type': DiveEmailTypes.TwoThirdBlast, + 'comment': 'Healthcare Dive Two Third Blast with param-type blast name', + }, + { + 'input': { + 'blast_id' : 35893250, + 'email_count': 57400, + 'labels' : ['Blast'], + 'list' : 'Healthcare Dive TWO Third Blast List - Group B', + 'mode': 'email', + 'modify_time' : 'Mon, 01 Jul 2024 10:20:29 -0400', + 'modify_user' : 'xxx@industrydive.com', + # Intentionally editing 'name' blast param to test inference from 'list' value + 'name': 'client_name=CorroHealth&pt_id=a12PE000000L2bnYAC&blast=incorrectblastparam&site=HealthcareDive&send_date=07.09.2024', + 'from_name' : 'Healthcare Dive', + 'status' : 'created', + 'subject' : 'Boost Hospital Revenue 7X with AI', + 'suppress_list' : [], + }, + 'expected_publication': 'Healthcare Dive', + 'expected_type': DiveEmailTypes.TwoThirdBlast, + 'comment': 'Healthcare Dive Two Third Blast with expected list name', + }, # You can pull the data for these tests from sailthru_tools scripts/get_campaign.py ] diff --git a/setup.py b/setup.py index c8d6d7f..bdd3b17 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="dive_sailthru_client", - version="0.0.25", + version="0.0.26", description="Industry Dive abstraction of the Sailthru API client", author='Industry Dive', author_email='tech.team@industrydive.com',