"""Task to read TSV from S3 and load data into art_relations.publishing_escrow.""" from hooks.art_relations_mysql_hook import ArtRelationsMySqlHook from lib.utils import ows from lib.utils.aws import file_exists from tasks.accounting_run_commit.helpers import build_mechanical_export_location from tasks.accounting_run_commit.helpers import get_event_from_params from templates.accounting_run_commit.mysql_load_mech_results_into_publishing_escrow \ import load_mechanical_deduction_results_into_publishing_escrow def load_mech_results_into_publishing_escrow_task(dag_run: dict, **kwargs) -> None: """Read mech deduction results from S3 and load into art_relations.publishing_escrow. Args: dag_run (dict): the dag's config """ event = get_event_from_params(dag_run, **kwargs) accounting_run_id = event.target_id accounting_run = ows.get_accounting_run_details(accounting_run_id) accounting_period_id = accounting_run.get('accounting_period_id') accounting_period = ows.get_accounting_period_details(accounting_period_id) mech_results_location = build_mechanical_export_location( accounting_period, accounting_run ) if file_exists(mech_results_location.url): sql_statement = load_mechanical_deduction_results_into_publishing_escrow() \ .render(s3_url=mech_results_location.url) hook = ArtRelationsMySqlHook() hook.run(sql_statement)