Skip to content

Commit 38a0b20

Browse files
authored
Update Parking_interim_cycle_hangar_waiting_list.py (#2055)
Add opt-in (OUT) email addresses
1 parent c823292 commit 38a0b20

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

scripts/jobs/parking/Parking_interim_cycle_hangar_waiting_list.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
additional fields (telephone Number, etc).
2222
2323
23/12/2024 - Create SQL
24+
06/01/2025 - add unsubscribed email
25+
13/01/2025 - add opt-in data
2426
*********************************************************************************/
2527
With Interim_Wait as (
2628
SELECT
@@ -61,16 +63,33 @@
6163
From "dataplatform-stg-liberator-raw-zone".liberator_licence_party
6264
WHERE import_Date = format_datetime(current_date, 'yyyyMMdd')),
6365
64-
/*** obtain the emails (from Tom) of those parties that are NOT interested in a Hangar***/
66+
/*** 06/01/2024 - obtain the emails (from Tom) of those parties that are NOT interested in a Hangar***/
6567
unsubscribed_emails as (
6668
SELECT *,
6769
ROW_NUMBER() OVER ( PARTITION BY email_address ORDER BY email_address DESC) row1
6870
FROM "parking-raw-zone".parking_parking_cycle_hangar_unsubscribed_emails
6971
WHERE import_date = (select max(import_date)
70-
from "parking-raw-zone".parking_parking_cycle_hangar_unsubscribed_emails))
72+
from "parking-raw-zone".parking_parking_cycle_hangar_unsubscribed_emails)),
73+
74+
/*** 13/01/2025 added ***/
75+
opt_in_emails as (
76+
SELECT
77+
please_note_your_email_address_has_been_prefilled_based_on_your_account_registration_please_do_not_amend_this as email,
78+
please_select_one_of_the_options_below,
79+
ROW_NUMBER() OVER ( PARTITION BY please_note_your_email_address_has_been_prefilled_based_on_your_account_registration_please_do_not_amend_this
80+
ORDER BY please_note_your_email_address_has_been_prefilled_based_on_your_account_registration_please_do_not_amend_this
81+
DESC) row1
82+
FROM "parking-raw-zone".parking_parking_opt_in_form_responses
83+
WHERE import_date = (select max(import_date)
84+
from "parking-raw-zone".parking_parking_opt_in_form_responses)
85+
AND please_select_one_of_the_options_below like 'No.%')
7186
7287
SELECT
73-
A.*, cast(D.telephone_number as varchar) as Telephone_Number, C.address2 as Street, B.housing_estate, E.email_address,
88+
A.*, cast(D.telephone_number as varchar) as Telephone_Number, C.address2 as Street, B.housing_estate,
89+
CASE
90+
When length(E.email_address) > 1 Then E.email_address
91+
When length(F.email)> 1 Then F.email
92+
END as email_address,
7493
7594
format_datetime(CAST(CURRENT_TIMESTAMP AS timestamp),
7695
'yyyy-MM-dd HH:mm:ss') AS import_date_timestamp,
@@ -85,7 +104,9 @@
85104
LEFT JOIN STREET_LLPG as C ON B.USRN = C.USRN
86105
LEFT JOIN Party as D ON A.party_id = D.business_party_id
87106
LEFT JOIN unsubscribed_emails as E ON upper(ltrim(rtrim(A.email))) = upper(ltrim(rtrim(E.email_address)))
88-
AND row1 = 1
107+
AND E.row1 = 1
108+
LEFT JOIN opt_in_emails as F ON upper(ltrim(rtrim(A.email))) = upper(ltrim(rtrim(F.email)))
109+
AND F.row1 = 1
89110
"""
90111

91112
create_update_table_with_partition(

0 commit comments

Comments
 (0)