From e6823c4af4198eeff7e3ec8706196c3a44d00630 Mon Sep 17 00:00:00 2001 From: Charlie Bini <5003326+cbini@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:03:23 +0000 Subject: [PATCH] refactor: use fromisoformat --- src/teamster/libraries/alchemer/sensors.py | 4 +--- src/teamster/libraries/amplify/dibels/assets.py | 4 ++-- src/teamster/libraries/deanslist/assets.py | 8 ++++---- src/teamster/libraries/schoolmint/grow/assets.py | 2 +- src/teamster/libraries/titan/assets.py | 2 +- src/teamster/libraries/zendesk/assets.py | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/teamster/libraries/alchemer/sensors.py b/src/teamster/libraries/alchemer/sensors.py index 33c41e8c6..b76ab7d36 100644 --- a/src/teamster/libraries/alchemer/sensors.py +++ b/src/teamster/libraries/alchemer/sensors.py @@ -45,9 +45,7 @@ def _sensor(context: SensorEvaluationContext, alchemer: AlchemerResource): context.log.info(msg=survey_obj["title"]) survey_id = survey_obj["id"] - modified_on = datetime.strptime( - survey_obj["modified_on"], "%Y-%m-%d HH:mm:ss" - ) + modified_on = datetime.fromisoformat(survey_obj["modified_on"]) survey_cursor_timestamp = cursor.get(survey_id) diff --git a/src/teamster/libraries/amplify/dibels/assets.py b/src/teamster/libraries/amplify/dibels/assets.py index 28b051573..0e618eded 100644 --- a/src/teamster/libraries/amplify/dibels/assets.py +++ b/src/teamster/libraries/amplify/dibels/assets.py @@ -44,8 +44,8 @@ def build_amplify_dds_report_asset( def _asset(context: AssetExecutionContext, dds: DibelsDataSystemResource): partition_key = _check.inst(obj=context.partition_key, ttype=MultiPartitionKey) - date_partition_key = datetime.strptime( - partition_key.keys_by_dimension["date"], "%Y-%m-%d" + date_partition_key = datetime.fromisoformat( + partition_key.keys_by_dimension["date"] ) if report == "DataFarming": diff --git a/src/teamster/libraries/deanslist/assets.py b/src/teamster/libraries/deanslist/assets.py index 67127a8fb..fa62c45b5 100644 --- a/src/teamster/libraries/deanslist/assets.py +++ b/src/teamster/libraries/deanslist/assets.py @@ -101,8 +101,8 @@ def _asset(context: AssetExecutionContext, deanslist: DeansListResource): partition_key = _check.inst(obj=context.partition_key, ttype=MultiPartitionKey) date_partition_def = partitions_def.get_partitions_def_for_dimension("date") - date_partition_key = datetime.strptime( - partition_key.keys_by_dimension["date"], "%Y-%m-%d" + date_partition_key = datetime.fromisoformat( + partition_key.keys_by_dimension["date"] ) date_partition_key_fy = FiscalYear(datetime=date_partition_key, start_month=7) @@ -166,8 +166,8 @@ def build_deanslist_paginated_multi_partition_asset( def _asset(context: AssetExecutionContext, deanslist: DeansListResource): partition_key = _check.inst(obj=context.partition_key, ttype=MultiPartitionKey) - date_partition_key = datetime.strptime( - partition_key.keys_by_dimension["date"], "%Y-%m-%d" + date_partition_key = datetime.fromisoformat( + partition_key.keys_by_dimension["date"] ) date_partition_key_fy = FiscalYear(datetime=date_partition_key, start_month=7) diff --git a/src/teamster/libraries/schoolmint/grow/assets.py b/src/teamster/libraries/schoolmint/grow/assets.py index 6c843aca6..364811bab 100644 --- a/src/teamster/libraries/schoolmint/grow/assets.py +++ b/src/teamster/libraries/schoolmint/grow/assets.py @@ -36,7 +36,7 @@ def _asset(context: AssetExecutionContext, schoolmint_grow: SchoolMintGrowResour archived_key = partition_key.keys_by_dimension["archived"] last_modified_key = partition_key.keys_by_dimension["last_modified"] - last_modified_datetime = datetime.strptime(last_modified_key, "%Y-%m-%d") + last_modified_datetime = datetime.fromisoformat(last_modified_key) last_modified_end = last_modified_datetime.replace( hour=23, minute=59, second=59, microsecond=999999 diff --git a/src/teamster/libraries/titan/assets.py b/src/teamster/libraries/titan/assets.py index 0af556cbf..dfcbf6ab7 100644 --- a/src/teamster/libraries/titan/assets.py +++ b/src/teamster/libraries/titan/assets.py @@ -14,7 +14,7 @@ def build_titan_sftp_asset( current_fiscal_year: FiscalYear, ): start_fy = FiscalYear( - datetime=datetime.strptime(partition_start_date, "%Y-%m-%d"), start_month=7 + datetime=datetime.fromisoformat(partition_start_date), start_month=7 ) partition_keys = [ diff --git a/src/teamster/libraries/zendesk/assets.py b/src/teamster/libraries/zendesk/assets.py index 96446dae2..4f0616e77 100644 --- a/src/teamster/libraries/zendesk/assets.py +++ b/src/teamster/libraries/zendesk/assets.py @@ -32,7 +32,7 @@ def build_ticket_metrics_archive(code_location, timezone, avro_schema): def _asset(context: AssetExecutionContext, zendesk: ZendeskResource): partition_key = _check.not_none(value=context.partition_key) - partition_key_datetime = datetime.strptime(partition_key, "") + partition_key_datetime = datetime.fromisoformat(partition_key) data_filepath = pathlib.Path("env/ticket_metrics_archive/data.avro") schema = parse_schema(schema=avro_schema)