Upload 3 files
Browse files- app.py +3 -7
- payment_queries.py +332 -0
- payments.py +293 -0
app.py
CHANGED
|
@@ -66,7 +66,7 @@ menu_options = [
|
|
| 66 |
{"label": "Invoice splitter", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
| 67 |
{"label": "Seller sale validation", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
| 68 |
# {"label": "MID checker", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
| 69 |
-
{"label": "
|
| 70 |
]
|
| 71 |
|
| 72 |
# Create the custom option menu
|
|
@@ -405,12 +405,8 @@ elif selected_option == "Seller sale validation":
|
|
| 405 |
with open('seller.py') as file:
|
| 406 |
exec(file.read())
|
| 407 |
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
# exec(file.read())
|
| 411 |
-
|
| 412 |
-
elif selected_option == "Fynder":
|
| 413 |
-
with open('bot.py') as file:
|
| 414 |
exec(file.read())
|
| 415 |
|
| 416 |
|
|
|
|
| 66 |
{"label": "Invoice splitter", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
| 67 |
{"label": "Seller sale validation", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
| 68 |
# {"label": "MID checker", "icon": "π", "description": "Schedule an email with BigQuery data"},
|
| 69 |
+
{"label": "Payment working", "icon": "π", "description": "Schedule an email with BigQuery data"}
|
| 70 |
]
|
| 71 |
|
| 72 |
# Create the custom option menu
|
|
|
|
| 405 |
with open('seller.py') as file:
|
| 406 |
exec(file.read())
|
| 407 |
|
| 408 |
+
elif selected_option == "Payment working":
|
| 409 |
+
with open('payments.py') as file:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
exec(file.read())
|
| 411 |
|
| 412 |
|
payment_queries.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
group by
|
| 11 |
+
1
|
| 12 |
+
having
|
| 13 |
+
count(merged) <> 1
|
| 14 |
+
''',
|
| 15 |
+
|
| 16 |
+
'2. Checking already paid data showing in outstanding file': '''
|
| 17 |
+
select
|
| 18 |
+
merged,
|
| 19 |
+
paid_settled_merged_transaction,
|
| 20 |
+
REGEXP_CONTAINS(paid_settled_merged_transaction, CONCAT(r'(^|,)', merged, r'(,|$)')) as cc1,
|
| 21 |
+
from
|
| 22 |
+
`fynd-db.Outstanding.09_Payable_File_table` as A
|
| 23 |
+
where
|
| 24 |
+
REGEXP_CONTAINS(paid_settled_merged_transaction, CONCAT(r'(^|,)', merged, r'(,|$)')) <> false
|
| 25 |
+
''',
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
'3. Checking return transaction not having sale transaction': '''
|
| 29 |
+
select
|
| 30 |
+
bag_id,
|
| 31 |
+
paid_settled_merged_transaction,
|
| 32 |
+
count(bag_id) as bag_count,
|
| 33 |
+
from
|
| 34 |
+
`fynd-db.Outstanding.09_Payable_File_table`
|
| 35 |
+
where
|
| 36 |
+
bag_id in
|
| 37 |
+
(select
|
| 38 |
+
bag_id,
|
| 39 |
+
-- merged,
|
| 40 |
+
-- paid_settled_merged_transaction,
|
| 41 |
+
-- REGEXP_CONTAINS(paid_settled_merged_transaction, CONCAT(r'(^|,)', merged, r'(,|$)')) as cc1,
|
| 42 |
+
from
|
| 43 |
+
`fynd-db.Outstanding.09_Payable_File_table` as A
|
| 44 |
+
where
|
| 45 |
+
transaction_type = 'Return'
|
| 46 |
+
and paid_settled_merged_transaction is null)
|
| 47 |
+
group by
|
| 48 |
+
1,2
|
| 49 |
+
having
|
| 50 |
+
count(bag_id) = 1
|
| 51 |
+
order by
|
| 52 |
+
1 asc
|
| 53 |
+
''',
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
'4. Checking old data inserted in 09_net_collection table': '''
|
| 57 |
+
SELECT
|
| 58 |
+
A.bag_id,
|
| 59 |
+
A.collection_partner,
|
| 60 |
+
A.Settlement_type,
|
| 61 |
+
A.inserted_date,
|
| 62 |
+
B.bag_id,
|
| 63 |
+
B.Transaction_type,
|
| 64 |
+
C.bag_id,
|
| 65 |
+
C.settlement_type,
|
| 66 |
+
D.bag_id
|
| 67 |
+
FROM
|
| 68 |
+
`fynd-db.finance_recon_tool_asia.01_finance_avis_data_final` AS A
|
| 69 |
+
LEFT JOIN
|
| 70 |
+
`fynd-db.finance_dwh.Brand_Settlement_pulse` AS B
|
| 71 |
+
ON A.bag_id = B.bag_id
|
| 72 |
+
LEFT JOIN
|
| 73 |
+
`fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily` AS C
|
| 74 |
+
ON A.bag_id = C.bag_id
|
| 75 |
+
LEFT JOIN
|
| 76 |
+
`fynd-db.finance_recon_tool_asia.05_partner_collection` AS D
|
| 77 |
+
ON A.bag_id = D.bag_id
|
| 78 |
+
WHERE
|
| 79 |
+
A.Settlement_type <> 'NA'
|
| 80 |
+
and date(A.inserted_date) > '2024-07-31'
|
| 81 |
+
AND B.bag_id IS NOT NULL
|
| 82 |
+
AND C.bag_id IS NOT NULL
|
| 83 |
+
AND D.bag_id IS NOT NULL
|
| 84 |
+
AND (
|
| 85 |
+
CASE
|
| 86 |
+
WHEN A.Settlement_type = 'collection' THEN 'Sale'
|
| 87 |
+
WHEN A.Settlement_type = 'refund' THEN 'Return'
|
| 88 |
+
ELSE 'Claim'
|
| 89 |
+
END
|
| 90 |
+
) = B.Transaction_type
|
| 91 |
+
GROUP BY
|
| 92 |
+
1,2,3,4,5,6,7,8,9
|
| 93 |
+
''',
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
'5. Checking whether expected payout date is null': '''
|
| 97 |
+
SELECT
|
| 98 |
+
*
|
| 99 |
+
FROM
|
| 100 |
+
`fynd-db.Outstanding.09_Payable_File_table`
|
| 101 |
+
where
|
| 102 |
+
expected_payout_date is null
|
| 103 |
+
''',
|
| 104 |
+
|
| 105 |
+
'6. Validation for seller net collection formula': '''
|
| 106 |
+
SELECT
|
| 107 |
+
distinct
|
| 108 |
+
bag_id,
|
| 109 |
+
transaction_type,
|
| 110 |
+
settlement_type,
|
| 111 |
+
round(esp-seller_discounts-bca,0) BCA_Diff,
|
| 112 |
+
round(bca-seller_tender_value-tcs_on_vog-tds_on_bca+seller_fees-seller_net_collection,0) Seller_net_collection_diff
|
| 113 |
+
FROM
|
| 114 |
+
`fynd-db.Outstanding.09_Payable_File_table`
|
| 115 |
+
where
|
| 116 |
+
round(esp-seller_discounts-bca,0) not in (0,1)
|
| 117 |
+
and round(bca-seller_tender_value-tcs_on_vog-tds_on_bca+seller_fees-seller_net_collection,0) not in (0,1)
|
| 118 |
+
''',
|
| 119 |
+
|
| 120 |
+
'7. Checking sign for payout, refund & claim ': '''
|
| 121 |
+
SELECT
|
| 122 |
+
*,
|
| 123 |
+
CASE
|
| 124 |
+
WHEN (settlement_type = 'collection' AND bca >= 0) THEN 'MATCH'
|
| 125 |
+
WHEN (settlement_type = 'refund' AND bca <= 0) THEN 'MATCH'
|
| 126 |
+
WHEN (settlement_type = 'Claim' AND bca >= 0) THEN 'MATCH'
|
| 127 |
+
ELSE 'NOT MATCH'
|
| 128 |
+
END AS comment
|
| 129 |
+
FROM
|
| 130 |
+
`fynd-db.Outstanding.09_Payable_File_table`
|
| 131 |
+
WHERE
|
| 132 |
+
--settlement_type ='collection' and
|
| 133 |
+
settlement_type in ('collection','refund','cliam') and
|
| 134 |
+
NOT (
|
| 135 |
+
(settlement_type = 'collection' AND bca >= 0)
|
| 136 |
+
OR
|
| 137 |
+
(settlement_type = 'refund' AND bca <= 0)
|
| 138 |
+
OR
|
| 139 |
+
(settlement_type = 'claim' AND bca >= 0)
|
| 140 |
+
)
|
| 141 |
+
''',
|
| 142 |
+
|
| 143 |
+
'8. Checking TCS & TDS': '''
|
| 144 |
+
SELECT
|
| 145 |
+
distinct
|
| 146 |
+
bag_id,
|
| 147 |
+
settlement_type,
|
| 148 |
+
segement_code,
|
| 149 |
+
tcs_on_vog,
|
| 150 |
+
tds_on_bca,
|
| 151 |
+
case when segement_code not in ('FY','UN') and tcs_on_vog = 0 then 'Match'
|
| 152 |
+
when segement_code not in ('FY','UN') and tds_on_bca = 0 then 'Match'
|
| 153 |
+
when segement_code in ('FY','UN') and tcs_on_vog <> 0 and tds_on_bca <> 0 then 'Match' else "Not Match" end as Check
|
| 154 |
+
FROM
|
| 155 |
+
`fynd-db.Outstanding.09_Payable_File_table`
|
| 156 |
+
where
|
| 157 |
+
(case when segement_code not in ('FY','UN') and tcs_on_vog = 0 then 'Match'
|
| 158 |
+
when segement_code not in ('FY','UN') and tds_on_bca = 0 then 'Match'
|
| 159 |
+
when segement_code in ('FY','UN') and tcs_on_vog <> 0 and tds_on_bca <> 0 then 'Match' else "Not Match" end) = 'Not Match'
|
| 160 |
+
''',
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
'9. Collection done but data not updated in 09_net_collection': '''
|
| 164 |
+
with status as (SELECT
|
| 165 |
+
Company_id,
|
| 166 |
+
Company_name,
|
| 167 |
+
Bagid,
|
| 168 |
+
Placed_date,
|
| 169 |
+
Cancelled_date,
|
| 170 |
+
bag_invoiced,
|
| 171 |
+
RTO_delivered_date,
|
| 172 |
+
Delivered_date,
|
| 173 |
+
FROM
|
| 174 |
+
`fynd-db.finance_asia_dwh.Bag_Audit_review`),
|
| 175 |
+
error_bags as (
|
| 176 |
+
SELECT
|
| 177 |
+
bag_id
|
| 178 |
+
FROM `fynd-db.finance_recon_tool_asia.03_error_view_data`
|
| 179 |
+
WHERE
|
| 180 |
+
resolve_date is null
|
| 181 |
+
)
|
| 182 |
+
SELECT
|
| 183 |
+
DISTINCT
|
| 184 |
+
C.Company_id,
|
| 185 |
+
C.Company_name,
|
| 186 |
+
A.bag_id AS COLLECTED_BAG,
|
| 187 |
+
B.bag_id AS SETTLEMENT_BAG,
|
| 188 |
+
D.bag_id AS error_BAG,
|
| 189 |
+
A.order_type,
|
| 190 |
+
Placed_date,
|
| 191 |
+
Cancelled_date,
|
| 192 |
+
bag_invoiced,
|
| 193 |
+
RTO_delivered_date,
|
| 194 |
+
Delivered_date
|
| 195 |
+
FROM
|
| 196 |
+
`fynd-db.finance_recon_tool_asia.05_partner_collection` AS A
|
| 197 |
+
left join
|
| 198 |
+
(SELECT
|
| 199 |
+
DISTINCT
|
| 200 |
+
bag_id
|
| 201 |
+
FROM `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
| 202 |
+
WHERE
|
| 203 |
+
Settlement_type = 'collection'
|
| 204 |
+
) AS B
|
| 205 |
+
ON
|
| 206 |
+
A.bag_id = B.bag_id
|
| 207 |
+
left join
|
| 208 |
+
status as C
|
| 209 |
+
on
|
| 210 |
+
A.bag_id = C.Bagid
|
| 211 |
+
left join
|
| 212 |
+
error_bags as D
|
| 213 |
+
on
|
| 214 |
+
A.bag_id = D.bag_id
|
| 215 |
+
WHERE
|
| 216 |
+
receipt_date >= '2023-04-01'
|
| 217 |
+
and net_remitted <> 0
|
| 218 |
+
and C.Company_id not in (select
|
| 219 |
+
test_company
|
| 220 |
+
from `fynd-db.finance_dwh.test_details`)
|
| 221 |
+
AND B.bag_id IS NULL
|
| 222 |
+
and Delivered_date is not null
|
| 223 |
+
AND D.bag_id IS NULL
|
| 224 |
+
''',
|
| 225 |
+
|
| 226 |
+
'10. Refund done but data not updated in 09_net_collection': '''
|
| 227 |
+
with status as (SELECT
|
| 228 |
+
Company_id,
|
| 229 |
+
Company_name,
|
| 230 |
+
Ordering_channel,
|
| 231 |
+
Bagid,
|
| 232 |
+
Placed_date,
|
| 233 |
+
Cancelled_date,
|
| 234 |
+
bag_invoiced,
|
| 235 |
+
RTO_delivered_date,
|
| 236 |
+
Delivered_date,
|
| 237 |
+
Return_picked_date,
|
| 238 |
+
Return_delivered_date
|
| 239 |
+
FROM
|
| 240 |
+
`fynd-db.finance_asia_dwh.Bag_Audit_review`),
|
| 241 |
+
error_bags as (
|
| 242 |
+
SELECT
|
| 243 |
+
bag_id
|
| 244 |
+
FROM `fynd-db.finance_recon_tool_asia.03_error_view_data`
|
| 245 |
+
WHERE
|
| 246 |
+
resolve_date is null
|
| 247 |
+
)
|
| 248 |
+
SELECT
|
| 249 |
+
DISTINCT
|
| 250 |
+
C.Company_id,
|
| 251 |
+
C.Company_name,
|
| 252 |
+
C.Ordering_channel,
|
| 253 |
+
A.bag_id AS COLLECTED_BAG,
|
| 254 |
+
B.bag_id AS SETTLEMENT_BAG,
|
| 255 |
+
D.bag_id AS error_BAG,
|
| 256 |
+
A.order_type,
|
| 257 |
+
Placed_date,
|
| 258 |
+
Cancelled_date,
|
| 259 |
+
bag_invoiced,
|
| 260 |
+
RTO_delivered_date,
|
| 261 |
+
Delivered_date,
|
| 262 |
+
Return_picked_date,
|
| 263 |
+
Return_delivered_date
|
| 264 |
+
FROM
|
| 265 |
+
`fynd-db.finance_recon_tool_asia.05_partner_refunds` AS A
|
| 266 |
+
left join
|
| 267 |
+
(SELECT
|
| 268 |
+
DISTINCT
|
| 269 |
+
bag_id
|
| 270 |
+
FROM `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
| 271 |
+
WHERE
|
| 272 |
+
Settlement_type = 'refund'
|
| 273 |
+
) AS B
|
| 274 |
+
ON
|
| 275 |
+
A.bag_id = B.bag_id
|
| 276 |
+
left join
|
| 277 |
+
status as C
|
| 278 |
+
on
|
| 279 |
+
A.bag_id = C.Bagid
|
| 280 |
+
left join
|
| 281 |
+
error_bags as D
|
| 282 |
+
on
|
| 283 |
+
A.bag_id = D.bag_id
|
| 284 |
+
WHERE
|
| 285 |
+
refund_date >= '2023-04-01'
|
| 286 |
+
and net_refunded <> 0
|
| 287 |
+
and C.Company_id not in (select
|
| 288 |
+
test_company
|
| 289 |
+
from `fynd-db.finance_dwh.test_details`)
|
| 290 |
+
AND B.bag_id IS NULL
|
| 291 |
+
and C.Company_id not in (507)
|
| 292 |
+
and (case when Ordering_channel in ('FYND','UNIKET') and Return_picked_date is not null then 'yes'
|
| 293 |
+
when Ordering_channel not in ('FYND','UNIKET') and Return_delivered_date is not null then 'yes' else 'no' end) = 'yes'
|
| 294 |
+
AND D.bag_id IS NULL
|
| 295 |
+
''',
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
'11. Checking for duplicate count in 09_net_collection': '''
|
| 299 |
+
select
|
| 300 |
+
concat(bag_id,Settlement_type) as Merged,
|
| 301 |
+
count(concat(bag_id,Settlement_type))
|
| 302 |
+
from `fynd-db.finance_recon_tool_asia.09_seller_net_collection_daily`
|
| 303 |
+
group by
|
| 304 |
+
1
|
| 305 |
+
having
|
| 306 |
+
count(concat(bag_id,Settlement_type)) not in (1)
|
| 307 |
+
''',
|
| 308 |
+
|
| 309 |
+
'12. Checking for presence of Non-RBL, Prepaid & Fynd/Uniket in 09_payable_file': '''
|
| 310 |
+
select
|
| 311 |
+
*
|
| 312 |
+
from
|
| 313 |
+
`fynd-db.Outstanding.09_Payable_File_table` A
|
| 314 |
+
where
|
| 315 |
+
order_type = 'PPD'
|
| 316 |
+
and
|
| 317 |
+
ordering_channel not in ('UNIKET', 'FYND')
|
| 318 |
+
and
|
| 319 |
+
A.Company_Type = 'Non RBL'
|
| 320 |
+
and collection_comment = 'collection_pending'
|
| 321 |
+
''',
|
| 322 |
+
|
| 323 |
+
'13. Checking for difference in collection': '''
|
| 324 |
+
select
|
| 325 |
+
*,
|
| 326 |
+
current_timestamp() as table_update_date
|
| 327 |
+
from
|
| 328 |
+
`fynd-db.Outstanding.09_Payable_File_table`
|
| 329 |
+
where
|
| 330 |
+
Collection_amount_comment = 'collection_diff'
|
| 331 |
+
'''
|
| 332 |
+
}
|
payments.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from google.cloud import bigquery
|
| 2 |
+
import functions_framework
|
| 3 |
+
from payment_queries import queries
|
| 4 |
+
from google.oauth2 import service_account
|
| 5 |
+
import json
|
| 6 |
+
import requests
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import pyperclip
|
| 9 |
+
from ap import send_message_via_webhook, Webhook_urls
|
| 10 |
+
|
| 11 |
+
# Dropdown for channels/members
|
| 12 |
+
webhook_url = list(Webhook_urls.keys())
|
| 13 |
+
html_subject = """
|
| 14 |
+
<html>
|
| 15 |
+
<head>
|
| 16 |
+
<style>
|
| 17 |
+
.button {
|
| 18 |
+
display: inline-block;
|
| 19 |
+
padding: 10px 20px;
|
| 20 |
+
border-radius: 12px;
|
| 21 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
| 22 |
+
box-shadow:
|
| 23 |
+
0 6px 12px rgba(0, 0, 0, 0.3),
|
| 24 |
+
0 8px 16px rgba(0, 0, 0, 0.2),
|
| 25 |
+
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
|
| 26 |
+
text-align: center;
|
| 27 |
+
position: relative;
|
| 28 |
+
transform: translateY(4px);
|
| 29 |
+
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
| 30 |
+
cursor: pointer;
|
| 31 |
+
user-select: none;
|
| 32 |
+
}
|
| 33 |
+
.button:hover {
|
| 34 |
+
box-shadow:
|
| 35 |
+
0 8px 16px rgba(0, 0, 0, 0.3),
|
| 36 |
+
0 12px 24px rgba(0, 0, 0, 0.2);
|
| 37 |
+
transform: translateY(2px);
|
| 38 |
+
}
|
| 39 |
+
.button:active {
|
| 40 |
+
box-shadow:
|
| 41 |
+
0 4px 8px rgba(0, 0, 0, 0.3),
|
| 42 |
+
0 6px 12px rgba(0, 0, 0, 0.2);
|
| 43 |
+
transform: translateY(0);
|
| 44 |
+
}
|
| 45 |
+
</style>
|
| 46 |
+
</head>
|
| 47 |
+
<body>
|
| 48 |
+
<div class="button">
|
| 49 |
+
<h3 style="
|
| 50 |
+
font-size: 20px;
|
| 51 |
+
color: #ffffff;
|
| 52 |
+
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
|
| 53 |
+
background-clip: text;
|
| 54 |
+
-webkit-background-clip: text;
|
| 55 |
+
text-fill-color: transparent;
|
| 56 |
+
-webkit-text-fill-color: transparent;
|
| 57 |
+
margin: 0;
|
| 58 |
+
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 59 |
+
">Select channels/members</h3>
|
| 60 |
+
</div>
|
| 61 |
+
</body>
|
| 62 |
+
</html>
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
| 67 |
+
selection = st.multiselect("", webhook_url)
|
| 68 |
+
# SLACK_WEBHOOK_URL = "https://hooks.slack.com/services/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"
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def check_duplicates(credentials_file):
|
| 73 |
+
"""Check for duplicates using BigQuery with the provided credentials file."""
|
| 74 |
+
results = {}
|
| 75 |
+
# credentials = service_account.Credentials.from_service_account_info(json.loads(credentials_file))
|
| 76 |
+
|
| 77 |
+
credentials = service_account.Credentials.from_service_account_info(
|
| 78 |
+
json.loads(credentials_file),
|
| 79 |
+
scopes=[
|
| 80 |
+
"https://www.googleapis.com/auth/cloud-platform",
|
| 81 |
+
"https://www.googleapis.com/auth/drive.readonly" # Include if accessing external Drive resources
|
| 82 |
+
]
|
| 83 |
+
)
|
| 84 |
+
client = bigquery.Client(credentials=credentials, project=credentials.project_id)
|
| 85 |
+
|
| 86 |
+
for i, (query_name, query) in enumerate(queries.items()):
|
| 87 |
+
|
| 88 |
+
query_job = client.query(query)
|
| 89 |
+
df = query_job.result().to_dataframe()
|
| 90 |
+
# For debugging, write the DataFrame to the Streamlit app
|
| 91 |
+
st.write(f"{query_name}:", df)
|
| 92 |
+
|
| 93 |
+
button_styles = """
|
| 94 |
+
<style>
|
| 95 |
+
div.stButton > button {
|
| 96 |
+
color: #ffffff; /* Text color */
|
| 97 |
+
font-size: 30px;
|
| 98 |
+
background-image: linear-gradient(to right, #800000, #ff0000); /* Maroon to light red gradient */
|
| 99 |
+
border: none;
|
| 100 |
+
padding: 10px 20px;
|
| 101 |
+
cursor: pointer;
|
| 102 |
+
border-radius: 15px;
|
| 103 |
+
display: inline-block;
|
| 104 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 15px rgba(0, 0, 0, 0.1); /* Box shadow */
|
| 105 |
+
transition: all 0.3s ease; /* Smooth transition on hover */
|
| 106 |
+
}
|
| 107 |
+
div.stButton > button:hover {
|
| 108 |
+
background-color: #00ff00; /* Hover background color */
|
| 109 |
+
color: #ff0000; /* Hover text color */
|
| 110 |
+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2), 0 12px 20px rgba(0, 0, 0, 0.2); /* Box shadow on hover */
|
| 111 |
+
}
|
| 112 |
+
</style>
|
| 113 |
+
"""
|
| 114 |
+
st.markdown(button_styles, unsafe_allow_html=True)
|
| 115 |
+
if st.button(f"Copy Query", key=f"copy_query_{i}"):
|
| 116 |
+
pyperclip.copy(query)
|
| 117 |
+
st.success('Query copied to clipboard!')
|
| 118 |
+
|
| 119 |
+
if not df.empty:
|
| 120 |
+
duplicate_count = len(df)
|
| 121 |
+
results[query_name] = duplicate_count
|
| 122 |
+
|
| 123 |
+
return results
|
| 124 |
+
|
| 125 |
+
# Streamlit UI
|
| 126 |
+
html_subject = """
|
| 127 |
+
<html>
|
| 128 |
+
<head>
|
| 129 |
+
<style>
|
| 130 |
+
.button {
|
| 131 |
+
display: inline-block;
|
| 132 |
+
padding: 10px 20px;
|
| 133 |
+
border-radius: 12px;
|
| 134 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
| 135 |
+
box-shadow:
|
| 136 |
+
0 6px 12px rgba(0, 0, 0, 0.3),
|
| 137 |
+
0 8px 16px rgba(0, 0, 0, 0.2),
|
| 138 |
+
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
|
| 139 |
+
text-align: center;
|
| 140 |
+
position: relative;
|
| 141 |
+
transform: translateY(4px);
|
| 142 |
+
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
| 143 |
+
cursor: pointer;
|
| 144 |
+
user-select: none;
|
| 145 |
+
}
|
| 146 |
+
.button:hover {
|
| 147 |
+
box-shadow:
|
| 148 |
+
0 8px 16px rgba(0, 0, 0, 0.3),
|
| 149 |
+
0 12px 24px rgba(0, 0, 0, 0.2);
|
| 150 |
+
transform: translateY(2px);
|
| 151 |
+
}
|
| 152 |
+
.button:active {
|
| 153 |
+
box-shadow:
|
| 154 |
+
0 4px 8px rgba(0, 0, 0, 0.3),
|
| 155 |
+
0 6px 12px rgba(0, 0, 0, 0.2);
|
| 156 |
+
transform: translateY(0);
|
| 157 |
+
}
|
| 158 |
+
</style>
|
| 159 |
+
</head>
|
| 160 |
+
<body>
|
| 161 |
+
<div class="button">
|
| 162 |
+
<h3 style="
|
| 163 |
+
font-size: 20px;
|
| 164 |
+
color: #ffffff;
|
| 165 |
+
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
|
| 166 |
+
background-clip: text;
|
| 167 |
+
-webkit-background-clip: text;
|
| 168 |
+
text-fill-color: transparent;
|
| 169 |
+
-webkit-text-fill-color: transparent;
|
| 170 |
+
margin: 0;
|
| 171 |
+
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 172 |
+
">Upload service a/c credentials</h3>
|
| 173 |
+
</div>
|
| 174 |
+
</body>
|
| 175 |
+
</html>
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
| 179 |
+
|
| 180 |
+
# Upload credentials file
|
| 181 |
+
credentials_file = st.file_uploader("", type="json")
|
| 182 |
+
|
| 183 |
+
if credentials_file is not None:
|
| 184 |
+
# Read the credentials file
|
| 185 |
+
credentials_data = credentials_file.read().decode("utf-8")
|
| 186 |
+
|
| 187 |
+
# Check for duplicates
|
| 188 |
+
results = check_duplicates(credentials_data)
|
| 189 |
+
st.write("")
|
| 190 |
+
st.write("")
|
| 191 |
+
|
| 192 |
+
if results:
|
| 193 |
+
# Define the HTML message with gradient text and extra spacing
|
| 194 |
+
html_subject = """
|
| 195 |
+
<html>
|
| 196 |
+
<head>
|
| 197 |
+
<style>
|
| 198 |
+
.button {
|
| 199 |
+
display: inline-block;
|
| 200 |
+
padding: 10px 20px;
|
| 201 |
+
border-radius: 12px;
|
| 202 |
+
background: linear-gradient(to bottom, #f8f9fa, #e0e0e0);
|
| 203 |
+
box-shadow:
|
| 204 |
+
0 6px 12px rgba(0, 0, 0, 0.3),
|
| 205 |
+
0 8px 16px rgba(0, 0, 0, 0.2),
|
| 206 |
+
inset 0 -2px 4px rgba(255, 255, 255, 0.6);
|
| 207 |
+
text-align: center;
|
| 208 |
+
position: relative;
|
| 209 |
+
transform: translateY(4px);
|
| 210 |
+
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
| 211 |
+
cursor: pointer;
|
| 212 |
+
user-select: none;
|
| 213 |
+
}
|
| 214 |
+
.button:hover {
|
| 215 |
+
box-shadow:
|
| 216 |
+
0 8px 16px rgba(0, 0, 0, 0.3),
|
| 217 |
+
0 12px 24px rgba(0, 0, 0, 0.2);
|
| 218 |
+
transform: translateY(2px);
|
| 219 |
+
}
|
| 220 |
+
.button:active {
|
| 221 |
+
box-shadow:
|
| 222 |
+
0 4px 8px rgba(0, 0, 0, 0.3),
|
| 223 |
+
0 6px 12px rgba(0, 0, 0, 0.2);
|
| 224 |
+
transform: translateY(0);
|
| 225 |
+
}
|
| 226 |
+
.spacing {
|
| 227 |
+
margin: 20px 0; /* Adjust the value as needed */
|
| 228 |
+
}
|
| 229 |
+
.result-box {
|
| 230 |
+
border: 1px solid #ddd;
|
| 231 |
+
border-radius: 8px;
|
| 232 |
+
background: #f9f9f9;
|
| 233 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 234 |
+
padding: 10px;
|
| 235 |
+
margin-bottom: 10px;
|
| 236 |
+
font-size: 16px;
|
| 237 |
+
}
|
| 238 |
+
.result-title {
|
| 239 |
+
font-weight: bold;
|
| 240 |
+
color: #333;
|
| 241 |
+
}
|
| 242 |
+
</style>
|
| 243 |
+
</head>
|
| 244 |
+
<body>
|
| 245 |
+
<div class="button">
|
| 246 |
+
<h3 style="
|
| 247 |
+
font-size: 20px;
|
| 248 |
+
color: #ffffff;
|
| 249 |
+
background-image: linear-gradient(to right, #800000, #ff0000, #ffdab9);
|
| 250 |
+
background-clip: text;
|
| 251 |
+
-webkit-background-clip: text;
|
| 252 |
+
text-fill-color: transparent;
|
| 253 |
+
-webkit-text-fill-color: transparent;
|
| 254 |
+
margin: 0;
|
| 255 |
+
text-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
| 256 |
+
">Duplicate Counts for Queries:</h3>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="spacing"></div> <!-- Adds spacing between the heading and the content -->
|
| 259 |
+
</body>
|
| 260 |
+
</html>
|
| 261 |
+
"""
|
| 262 |
+
|
| 263 |
+
# Display HTML message with spacing
|
| 264 |
+
st.markdown(html_subject, unsafe_allow_html=True)
|
| 265 |
+
|
| 266 |
+
# Prepare the plain text message with styled boxes
|
| 267 |
+
message_html = ""
|
| 268 |
+
for query_name, count in results.items():
|
| 269 |
+
message_html += f"""
|
| 270 |
+
<div class="result-box">
|
| 271 |
+
<div class="result-title">{query_name}</div>
|
| 272 |
+
<div>{count} records</div>
|
| 273 |
+
</div>
|
| 274 |
+
"""
|
| 275 |
+
|
| 276 |
+
# Display the styled message in Streamlit
|
| 277 |
+
st.markdown(message_html, unsafe_allow_html=True)
|
| 278 |
+
|
| 279 |
+
# Prepare plain text for Slack messages
|
| 280 |
+
message_text = ""
|
| 281 |
+
for query_name, count in results.items():
|
| 282 |
+
message_text += f"*{query_name}*\n{count}records\n\n"
|
| 283 |
+
|
| 284 |
+
if not results:
|
| 285 |
+
message_text = "No duplicates found in the queries."
|
| 286 |
+
|
| 287 |
+
# Send the message to selected channels
|
| 288 |
+
for channel in selection:
|
| 289 |
+
webhook_url = Webhook_urls.get(channel)
|
| 290 |
+
if webhook_url:
|
| 291 |
+
send_message_via_webhook(message_text, webhook_url)
|
| 292 |
+
else:
|
| 293 |
+
st.error(f"Webhook URL not found for channel: {channel}")
|