Skip to content

Commit

Permalink
優化程式碼架構
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Jan 10, 2025
1 parent 96faf13 commit 43d6a9e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
26 changes: 9 additions & 17 deletions a703_製作標音網頁.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ def logging_process_step(msg):


def process(wb):
# 指定虛擬環境的 Python 路徑
venv_python = os.path.join(".venv", "Scripts", "python.exe") if sys.platform == "win32" else os.path.join(".venv", "bin", "python")

# 獲取活頁簿的完整檔案路徑
file_path = wb.fullname
print(f"完整檔案路徑: {file_path}")

# 獲取活頁簿的檔案名稱(不包括路徑)
file_name = wb.name
print(f"檔案名稱: {file_name}")

# (1) 指定作業使用:【漢字注音】工作表
sheet = wb.sheets['漢字注音'] # 選擇工作表
sheet.activate() # 將「漢字注音」工作表設為作用中工作表
Expand All @@ -73,11 +62,14 @@ def process(wb):
return result_code

# (3) 依 env 工作表之設定,將檔案儲存至指定目錄。
save_as_new_file(wb=wb)
logging_process_step(f"儲存檔案至路徑:{file_path}")

# 作業正常結束
return EXIT_CODE_SUCCESS
file_path = save_as_new_file(wb=wb)
if not file_path:
logging.error("儲存檔案失敗!")
return EXIT_CODE_PROCESS_FAILURE
else:
logging_process_step(f"儲存檔案至路徑:{file_path}")
# 作業正常結束
return EXIT_CODE_SUCCESS


def main():
Expand Down Expand Up @@ -131,7 +123,7 @@ def main():
if __name__ == "__main__":
exit_code = main()
if exit_code == EXIT_CODE_SUCCESS:
print("作業正常完成!")
print("作業正常結束!")
else:
print(f"作業異常終結,異常碼為: {exit_code}")
sys.exit(exit_code)
4 changes: 1 addition & 3 deletions mod_file_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def save_as_new_file(wb):
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
except KeyError:
# print("未找到命名範圍 'TITLE',使用預設名稱")
# file_name = "default_file_name.xlsx" # 提供一個預設檔案名稱
setting_sheet = wb.sheets["env"]
file_name = str(setting_sheet.range("C4").value).strip()

Expand All @@ -41,7 +39,7 @@ def save_as_new_file(wb):

# 儲存新建立的工作簿
wb.save(new_file_path)
print(f"新檔案已儲存至: {new_file_path}")
return f"{new_file_path}"

#----------------------------------------------------------------
# 查詢語音類型,若未設定則預設為文讀音
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions process_log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ TypeError: can only concatenate str (not "NoneType") to str
2025-01-10 23:26:32,517 - INFO - 專案根目錄為: C:\work\Piau-Im
2025-01-10 23:26:44,341 - INFO - 儲存檔案至路徑:C:\work\Piau-Im\output7\【河洛白話注音-雅俗通】《尚有力量的每日祈禱文》.xlsx
2025-01-10 23:26:44,342 - INFO - 【漢字注音】工作表中已標音之漢字已輸出到網頁!
2025-01-10 23:46:54,794 - INFO - 作業開始
2025-01-10 23:46:54,795 - INFO - 專案根目錄為: C:\work\Piau-Im
2025-01-10 23:47:06,583 - INFO - 儲存檔案至路徑:.\output7\【河洛白話注音-雅俗通】《尚有力量的每日祈禱文》.xlsx
2025-01-10 23:47:06,584 - INFO - 製作【漢字標音】網頁己完成!

0 comments on commit 43d6a9e

Please sign in to comment.