-
Notifications
You must be signed in to change notification settings - Fork 11
Load CSV ticket data #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load CSV ticket data #181
Conversation
Lee-W
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is no longer part of a dag. should we move out and make it a separate project or put it in somewhere like cli/...
| """從文字檔載入 data 欄位名稱列表""" | ||
| logging.info(f"Loading data field names from {file_path}") | ||
| with file_path.open("r", encoding="utf-8") as f: | ||
| names = [line.strip() for line in f if line.strip()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| names = [line.strip() for line in f if line.strip()] | |
| names = [name for line in f if (name := line.strip())] |
| payload = [] | ||
| for event_raw_data in event_raw_data_array: | ||
| sanitized_event_raw_data = _sanitize_payload(event_raw_data) | ||
| payload.append(sanitized_event_raw_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| payload = [] | |
| for event_raw_data in event_raw_data_array: | |
| sanitized_event_raw_data = _sanitize_payload(event_raw_data) | |
| payload.append(sanitized_event_raw_data) | |
| payload = [ | |
| _sanitize_payload(event_raw_data) | |
| for event_raw_data in event_raw_data_array: | |
| ] |
| for record in payload[:5]: | ||
| print(json.dumps(record, indent=2, ensure_ascii=False)) | ||
|
|
||
| # save to payload.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # save to payload.json | |
| # save to payload.json |
| logging.info("資料成功載入 BigQuery。") | ||
|
|
||
| except Exception as e: | ||
| logging.error(f"執行過程中發生未預期的錯誤: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| logging.error(f"執行過程中發生未預期的錯誤: {e}") | |
| logging.exception(f"執行過程中發生未預期的錯誤: ") |
|
|
||
| def _load_to_bigquery(payload: list[dict]) -> None: | ||
| def load_to_bigquery_ods( | ||
| payload: list[dict], project_id: Optional[str], credential_file: Optional[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| payload: list[dict], project_id: Optional[str], credential_file: Optional[str] | |
| payload: list[dict], project_id: str | None, credential_file: str | None |
|
|
||
| def _load_to_bigquery_dwd(payload: list[dict]) -> None: | ||
| def load_to_bigquery_dwd( | ||
| payload: list[dict], project_id: Optional[str], credential_file: Optional[str], ticket_group: Optional[str] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| payload: list[dict], project_id: Optional[str], credential_file: Optional[str], ticket_group: Optional[str] = None | |
| payload: list[dict], project_id: str | None, credential_file: str | None, ticket_group: str | None = None |
|
Thanks for your review. I’ve moved this script into the ./cli folder. |
Types of changes
Description
2025 年開始無法直接透過 API 串接資料, 因此改開發一個匯入資料的腳本
cli/load_kktix_csv.py此腳本根據配置檔案與資料轉換格式為 API 的輸出, 目的是復用之前匯入資料庫的程式
dags/ods/kktix_ticket_orders/udfs/kktix_loader.py執行, 使用
tests/kktix_load_csv的測試資料示範腳本的參數說明可以使用
python cli/load_kktix_csv.py --help查看詳情已記錄於相關 文件
Checklist
make lintandmake testlocally to ensure all linter checks and testing pass