Skip to content

Commit bf46c69

Browse files
committed
refactor(dag:KKTIX_DISCORD_BOT_FOR_TEAM_REGISTRATION): improve typing and simplify logic
1 parent 0576d71 commit bf46c69

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

dags/app/team_registration_bot/dag.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@
3131
def KKTIX_DISCORD_BOT_FOR_TEAM_REGISTRATION():
3232
@task
3333
def LOAD_TO_DISCORD():
34+
webhook_url = Variable.get("discord_webhook_registration_endpoint")
3435
statistics = _get_statistics_from_bigquery()
35-
msg = _compose_discord_msg(statistics)
36-
kwargs = {
37-
"webhook_url": Variable.get("discord_webhook_registration_endpoint"),
38-
"username": "KKTIX order report",
39-
"msg": msg,
40-
}
41-
discord.send_webhook_message(**kwargs)
36+
discord.send_webhook_message(
37+
webhook_url=webhook_url,
38+
usernmae="KKTIX order report",
39+
msg=_compose_discord_msg(statistics),
40+
)
4241

4342
LOAD_TO_DISCORD()
4443

dags/app/team_registration_bot/udf.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _get_statistics_from_bigquery() -> dict:
3737
return result
3838

3939

40-
ticket_price = {
40+
ticket_price: dict[str, int] = {
4141
# please update the price for target year
4242
"企業票 - 一般階段 / Corporate - Regular Stage": 5800,
4343
"企業票 - 晚鳥階段 / Corporate - Final Stage": 6500,
@@ -55,14 +55,18 @@ def _get_statistics_from_bigquery() -> dict:
5555

5656

5757
def _compose_discord_msg(payload) -> str:
58-
msg = f"Hi 這是今天 {datetime.now().date()} 的票種統計資料,售票期結束後,請 follow README 的 `gcloud` 指令進去把 Airflow DAG 關掉\n\n"
58+
msg = (
59+
f"Hi 這是今天 {datetime.now().date()} 的票種統計資料,"
60+
"售票期結束後,請 follow README 的 `gcloud` 指令進去把 Airflow DAG 關掉\n\n"
61+
)
5962
total = 0
6063
total_income = 0
61-
for name, ticket_name, counts in payload:
64+
for _, ticket_name, counts in payload:
6265
msg += f" * 票種:{ticket_name}\t{counts}\n"
6366
total += counts
6467
total_income += ticket_price.get(ticket_name, 0) * counts
65-
total_income = f"{total_income:,}"
66-
msg += f"dashboard: https://metabase.pycon.tw/question/142?year={YEAR}\n"
67-
msg += f"總共賣出 {total} 張喔~ (總收入 TWD${total_income})"
68+
msg = (
69+
f"{msg}dashboard: https://metabase.pycon.tw/question/142?year={YEAR}\n"
70+
f"總共賣出 {total} 張喔~ (總收入 TWD${total_income:,})"
71+
)
6872
return msg

0 commit comments

Comments
 (0)