diff --git a/.vscode/launch.json b/.vscode/launch.json index cf36c13..b7f3aa4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,20 @@ // 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "a720_Thiam_Zu_Im", + "type": "debugpy", + "request": "launch", + "program": "a720_Thiam_Zu_Im.py", + "console": "integratedTerminal", + }, + { + "name": "a730_Tng_Bang_Iah", + "type": "debugpy", + "request": "launch", + "program": "a730_Tng_Bang_Iah.py", + "console": "integratedTerminal", + }, { "name": "a710_Thiam_Han_Ji_Tan_Piau_Im", "type": "debugpy", diff --git a/Tai_Gi_Zu_Im_Bun.xlsx b/Tai_Gi_Zu_Im_Bun.xlsx index 1e0f38b..b154389 100644 Binary files a/Tai_Gi_Zu_Im_Bun.xlsx and b/Tai_Gi_Zu_Im_Bun.xlsx differ diff --git a/Tai_Gi_Zu_Im_Bun_BAK.xlsx b/Tai_Gi_Zu_Im_Bun_BAK.xlsx index e0a4f51..5cf7624 100644 Binary files a/Tai_Gi_Zu_Im_Bun_BAK.xlsx and b/Tai_Gi_Zu_Im_Bun_BAK.xlsx differ diff --git a/a720_Thiam_Zu_Im.py b/a720_Thiam_Zu_Im.py index f0410bd..89c9d9c 100644 --- a/a720_Thiam_Zu_Im.py +++ b/a720_Thiam_Zu_Im.py @@ -1,74 +1,76 @@ +import getopt import math +import os +import sys import xlwings as xw - -def thiam_zu_im(file_name, sheet_name='漢字注音', cell='V3'): - # 打開 Excel 檔案 - wb = xw.Book(file_name) - - # 選擇工作表 - # sheet = wb.sheets[0] # 選擇第一個工作表 - sheet = wb.sheets[sheet_name] - - # 取得 V3 儲存格的字串 - v3_value = sheet.range(cell).value - - # 確認 V3 不為空 - if v3_value: - # 計算字串的總長度 - total_length = len(v3_value) - - # 每列最多處理 15 個字元,計算總共需要多少列 - chars_per_row = 15 - total_rows_needed = math.ceil(total_length / chars_per_row) # 無條件進位 - - # 清空 Row: 5, 9, 13, ... 漢字所在儲存格,上方的台語音標儲存格,及下方的台語注音符號儲存格 - row = 5 - for i in range(total_rows_needed): - for col in range(4, 19): # 【D欄=4】到【R欄=18】 - # 清空漢字所在儲存格 - # sheet.range((row, col)).value = None - - # 清空上方的台語音標儲存格 - sheet.range((row - 1, col)).value = None - - # 清空下方的台語注音符號儲存格 - sheet.range((row + 1, col)).value = None - - # 每處理 15 個字元後,換到下一行 - row += 4 - - # 逐行處理資料,從 Row 3 開始,每列處理 15 個字元 - row = 3 - for i in range(total_rows_needed): - for col in range(4, 19): # 【D欄=4】到【R欄=18】 - cell_value = sheet.range((row, col)).value # 取得 D4, E4, ..., R4 的內容 - - # 確認內容不為空 - if cell_value: - # 分割字串來提取羅馬拼音和台語注音 - lo_ma_ji = cell_value.split('〔')[1].split('〕')[0] # 取得〔羅馬拼音〕 - zu_im_hu_ho = cell_value.split('【')[1].split('】')[0] # 取得【台語注音】 - - # 將羅馬拼音填入當前 row + 1 的儲存格 - sheet.range((row + 1, col)).value = lo_ma_ji - - # 將台語注音填入當前 row + 3 的儲存格 - sheet.range((row + 3, col)).value = zu_im_hu_ho - - # 每處理 15 個字元後,換到下一行 - row += 4 - - print("已完成【台語音標】和【台語注音符號】標註工作。") +import settings +from p720_Thiam_Zu_Im import thiam_zu_im +from p730_Tng_Sing_Bang_Iah import tng_sing_bang_iah + + +def get_input_and_output_options(argv): + arg_input = "" + arg_output = "" + arg_user = "" + arg_help = "{0} -i -u -o ".format(argv[0]) + + try: + opts, args = getopt.getopt( # pyright: ignore + argv[1:], "hi:u:o:", ["help", "input=", "user=", "output="] + ) + except Exception as e: + print(e) + print(arg_help) + sys.exit(2) + + for opt, arg in opts: + if opt in ("-h", "--help"): + print(arg_help) # print the help message + sys.exit(2) + elif opt in ("-i", "--input"): + arg_input = arg + elif opt in ("-u", "--user"): + arg_user = arg + elif opt in ("-o", "--output"): + arg_output = arg + + print("input:", arg_input) + print("user:", arg_user) + print("output:", arg_output) + + return { + "input": arg_input, + "user": arg_user, + "output": arg_output, + } + + +if __name__ == "__main__": + # ========================================================================= + # (1) 取得需要注音的「檔案名稱」及其「目錄路徑」。 + # ========================================================================= + # 取得 Input 檔案名稱 + file_path = settings.get_tai_gi_zu_im_bun_path() + if not file_path: + print("未設定 .env 檔案") + # sys.exit(2) + opts = get_input_and_output_options(sys.argv) + if opts["input"] != "": + CONVERT_FILE_NAME = opts["input"] + else: + CONVERT_FILE_NAME = "Tai_Gi_Zu_Im_Bun.xlsx" + else: + CONVERT_FILE_NAME = file_path + print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") + + # ========================================================================= + # (2) 分析已輸入的【台語音標】及【台語注音符號】,將之各別填入漢字之上、下方。 + # - 上方:台語音標 + # - 下方:台語注音符號 + # ========================================================================= + thiam_zu_im(CONVERT_FILE_NAME) # 保存 Excel 檔案 - wb.save('Tai_Gi_Zu_Im_Bun.xlsx') # wb.close() - - # 令人工手動填入的台語音標和注音符號不要顯示 - - # 選擇名為 "顯示注音輸入" 的命名範圍 - named_range = wb.names['顯示注音輸入'] - - named_range.refers_to_range.value = False \ No newline at end of file diff --git a/a730_Tng_Bang_Iah.py b/a730_Tng_Bang_Iah.py new file mode 100644 index 0000000..8c01e02 --- /dev/null +++ b/a730_Tng_Bang_Iah.py @@ -0,0 +1,88 @@ +import getopt +import math +import os +import sys + +import xlwings as xw + +import settings +from p730_Tng_Sing_Bang_Iah import tng_sing_bang_iah + + +def get_input_and_output_options(argv): + arg_input = "" + arg_output = "" + arg_user = "" + arg_help = "{0} -i -u -o ".format(argv[0]) + + try: + opts, args = getopt.getopt( # pyright: ignore + argv[1:], "hi:u:o:", ["help", "input=", "user=", "output="] + ) + except Exception as e: + print(e) + print(arg_help) + sys.exit(2) + + for opt, arg in opts: + if opt in ("-h", "--help"): + print(arg_help) # print the help message + sys.exit(2) + elif opt in ("-i", "--input"): + arg_input = arg + elif opt in ("-u", "--user"): + arg_user = arg + elif opt in ("-o", "--output"): + arg_output = arg + + print("input:", arg_input) + print("user:", arg_user) + print("output:", arg_output) + + return { + "input": arg_input, + "user": arg_user, + "output": arg_output, + } + + +if __name__ == "__main__": + # ========================================================================= + # (1) 取得需要注音的「檔案名稱」及其「目錄路徑」。 + # ========================================================================= + # 取得 Input 檔案名稱 + file_path = settings.get_tai_gi_zu_im_bun_path() + if not file_path: + print("未設定 .env 檔案") + # sys.exit(2) + opts = get_input_and_output_options(sys.argv) + if opts["input"] != "": + CONVERT_FILE_NAME = opts["input"] + else: + CONVERT_FILE_NAME = "Tai_Gi_Zu_Im_Bun.xlsx" + else: + CONVERT_FILE_NAME = file_path + print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") + + # ========================================================================= + # (2) 將已注音之「漢字注音表」,製作成 HTML 格式之「注音/拼音/標音」網頁。 + # ========================================================================= + tng_sing_bang_iah(CONVERT_FILE_NAME) + + # ========================================================================= + # (3) 依據《文章標題》另存新檔。 + # ========================================================================= + wb = xw.Book(CONVERT_FILE_NAME) + setting_sheet = wb.sheets["env"] + new_file_name = str( + setting_sheet.range("C4").value + ).strip() + new_file_path = os.path.join( + ".\\output", + f"【河洛話注音】{new_file_name}" + ".xlsx") + + # 儲存新建立的工作簿 + wb.save(new_file_path) + + # 保存 Excel 檔案 + wb.close() diff --git a/docs/assets/styles/styles.css b/docs/assets/styles/styles.css index 18f1239..6fa186b 100644 --- a/docs/assets/styles/styles.css +++ b/docs/assets/styles/styles.css @@ -178,28 +178,25 @@ rtc { line-height: 1.8; } -.Siang_Pai rt { - font-family: Arial, Helvetica, sans-serif; - color: darkcyan; - font-size: 45%; - letter-spacing: 0; +rt { + font-family: Arial; + font-size: 40%; + color: green; + ruby-merge: merge; } -.Siang_Pai rtc { +rtc { font-family: BopomofoRuby; - color: #B94B6A; font-size: 30%; - line-height: normal; + color: #B94B6A; + ruby-merge: merge; - -webkit-ruby-position: inter-character; ruby-position: inter-character; text-orientation: upright; - letter-spacing: 0px; - -webkitg_writing-mode: vertical-lr; - writing-mode: vertical-lr; + writing-mode: vertical-rl; vertical-align: middle; - padding-right: 0.2em; + display: inline; } /* 台羅、閩拼、白話字 */ diff --git "a/docs/\345\257\222\347\252\257\350\263\246_\346\274\242\345\255\227\346\263\250\351\237\263.html" "b/docs/\345\257\222\347\252\257\350\263\246_\346\274\242\345\255\227\346\263\250\351\237\263.html" index 456d9b1..00ab235 100644 --- "a/docs/\345\257\222\347\252\257\350\263\246_\346\274\242\345\255\227\346\263\250\351\237\263.html" +++ "b/docs/\345\257\222\347\252\257\350\263\246_\346\274\242\345\255\227\346\263\250\351\237\263.html" @@ -11,492 +11,76 @@

- - - - thⁿi¹ - ( - ㄊㄧ¹ - ) - - - - - - u⁷ - ( - ㄨ⁷ - ) - - - - - - put⁴ - ( - ㄅㄨ⁴ - ) - - - - - - cik⁴ - ( - ㄑㄧ⁴ - ) - - - - - - hong¹ - ( - ㄏㄛㄥ¹ - ) - - - - - - hun⁵ - ( - ㄏㄨㄣ⁵ - ) - - +thiⁿ¹ㄊㆪˉ +u⁷ㄨ⁷ +put⁴ㄅㄨ +tshik⁴ㄑㄧ +hong¹ㄏㄛㄥˉ +hun⁵ㄏㄨㄣ⁵ - - - - lang⁵ - ( - ㄌㄤ⁵ - ) - - - - - - u⁷ - ( - ㄨ⁷ - ) - - - - - - tan³ - ( - ㄉㄢ³ - ) - - - - - - sik⁸ - ( - ㄒㄧ⁸ - ) - - - - - - ho⁷ - ( - ㄏㄜ⁷ - ) - - - - - - hok⁴ - ( - ㄏㄛ⁴ - ) - - +lang⁵ㄌㄤ⁵ +u⁷ㄨ⁷ +tan³ㄉㄢ³ +sik⁸ㄒㄧ⁸ +ho⁷ㄏㄜ⁷ +hok⁴ㄏㄛ⁴ - - - - ngoo⁵ - ( - ㄥㄛ⁵ - ) - - +ngoo⁵ㄥㄛ⁵
- - - - kang¹ - ( - ㄍㄤ¹ - ) - - - - - - pah⁴ - ( - ㄅㄚ⁴ - ) - - - - - - ziok⁴ - ( - ㄐㄧㄛ⁴ - ) - - +kang¹ㄍㄤ¹ +pah⁴ㄅㄚ⁴ +ziok⁴ㄐㄧㄛ⁴ - - - - kⁿia⁵ - ( - ㄍㄧㄚ⁵ - ) - - - - - - put⁴ - ( - ㄅㄨ⁴ - ) - - - - - - kip⁸ - ( - ㄍㄧ⁸ - ) - - - - - - zua⁵ - ( - ㄗㄨㄚ⁵ - ) - - +kⁿia⁵ㄍㄧㄚ⁵ +put⁴ㄅㄨ⁴ +kip⁸ㄍㄧ⁸ +zua⁵ㄗㄨㄚ⁵ - - - - hiong⁵ - ( - ㄏㄧㄛㄥ⁵ - ) - - - - - - ke¹ - ( - ㄍㄝ¹ - ) - - - - - - nng⁷ - ( - ㄋㄥ⁷ - ) - - - - - - sit⁸ - ( - ㄒㄧ⁸ - ) - - +hiong⁵ㄏㄧㄛㄥ⁵ +ke¹ㄍㄝ¹ +nng⁷ㄋㄥ⁷ +sit⁸ㄒㄧ⁸ - - - - pue¹ - ( - ㄅㄨㄝ¹ - ) - - +pue¹ㄅㄨㄝ¹
- - - - put⁴ - ( - ㄅㄨ⁴ - ) - - - - - - ko¹ - ( - ㄍㄜ¹ - ) - - - - - - - ( - ㄚ¹ - ) - - +put⁴ㄅㄨ⁴ +ko¹ㄍㄜ¹ +ㄚ¹ - - - - ma¹ - ( - ㄇㄚ¹ - ) - - - - - - u⁷ - ( - ㄨ⁷ - ) - - - - - - cian¹ - ( - ㄑㄧㄢ¹ - ) - - - - - - li² - ( - ㄌㄧ² - ) - - - - - - zi¹ - ( - ㄐㄧ¹ - ) - - - - - - ting⁵ - ( - ㄉㄧㄥ⁵ - ) - - +ma¹ㄇㄚ¹ +u⁷ㄨ⁷ +cian¹ㄑㄧㄢ¹ +li²ㄌㄧ² +zi¹ㄐㄧ¹ +ting⁵ㄉㄧㄥ⁵ - - - - bo⁵ - ( - ㄜ⁵ - ) - - - - - - khia⁵ - ( - ㄎㄧㄚ⁵ - ) - - - - - - put⁴ - ( - ㄅㄨ⁴ - ) - - - - - - lerng⁵ - ( - ㄌㄧㄥ⁵ - ) - - +bo⁵ㄜ⁵ +khia⁵ㄎㄧㄚ⁵ +put⁴ㄅㄨ⁴ +lerng⁵ㄌㄧㄥ⁵
- - - - zu⁷ - ( - ㄗㄨ⁷ - ) - - - - - - ong² - ( - ㄛㄥ² - ) - - +zu⁷ㄗㄨ⁷ +ong²ㄛㄥ² - - - - lang⁵ - ( - ㄌㄤ⁵ - ) - - - - - - u⁷ - ( - ㄨ⁷ - ) - - - - - - cong² - ( - ㄘㄛㄥ² - ) - - - - - - thⁿi¹ - ( - ㄊㄧ¹ - ) - - - - - - zi¹ - ( - ㄐㄧ¹ - ) - - - - - - zi³ - ( - ㄐㄧ³ - ) - - +lang⁵ㄌㄤ⁵ +u⁷ㄨ⁷ +cong²ㄘㄛㄥ² +thⁿi¹ㄊㄧ¹ +zi¹ㄐㄧ¹ +zi³ㄐㄧ³ - - - - hui¹ - ( - ㄏㄨㄧ¹ - ) - - - - - - un⁷ - ( - ㄨㄣ⁷ - ) - - - - - - put⁴ - ( - ㄅㄨ⁴ - ) - - - - - - lerng⁵ - ( - ㄌㄧㄥ⁵ - ) - - - - - - zu⁷ - ( - ㄗㄨ⁷ - ) - - +hui¹ㄏㄨㄧ¹ +un⁷ㄨㄣ⁷ +put⁴ㄅㄨ⁴ +lerng⁵ㄌㄧㄥ⁵ +zu⁷ㄗㄨ⁷
- - - - thong¹ - ( - ㄊㄛㄥ¹ - ) - - +thong¹ㄊㄛㄥ¹

diff --git "a/output/\343\200\220\346\262\263\346\264\233\350\251\261\346\263\250\351\237\263\343\200\221\345\257\222\347\252\257\350\263\246.xlsx" "b/output/\343\200\220\346\262\263\346\264\233\350\251\261\346\263\250\351\237\263\343\200\221\345\257\222\347\252\257\350\263\246.xlsx" new file mode 100644 index 0000000..8e87c89 Binary files /dev/null and "b/output/\343\200\220\346\262\263\346\264\233\350\251\261\346\263\250\351\237\263\343\200\221\345\257\222\347\252\257\350\263\246.xlsx" differ diff --git a/p720_Thiam_Zu_Im.py b/p720_Thiam_Zu_Im.py new file mode 100644 index 0000000..f0410bd --- /dev/null +++ b/p720_Thiam_Zu_Im.py @@ -0,0 +1,74 @@ +import math + +import xlwings as xw + + +def thiam_zu_im(file_name, sheet_name='漢字注音', cell='V3'): + # 打開 Excel 檔案 + wb = xw.Book(file_name) + + # 選擇工作表 + # sheet = wb.sheets[0] # 選擇第一個工作表 + sheet = wb.sheets[sheet_name] + + # 取得 V3 儲存格的字串 + v3_value = sheet.range(cell).value + + # 確認 V3 不為空 + if v3_value: + # 計算字串的總長度 + total_length = len(v3_value) + + # 每列最多處理 15 個字元,計算總共需要多少列 + chars_per_row = 15 + total_rows_needed = math.ceil(total_length / chars_per_row) # 無條件進位 + + # 清空 Row: 5, 9, 13, ... 漢字所在儲存格,上方的台語音標儲存格,及下方的台語注音符號儲存格 + row = 5 + for i in range(total_rows_needed): + for col in range(4, 19): # 【D欄=4】到【R欄=18】 + # 清空漢字所在儲存格 + # sheet.range((row, col)).value = None + + # 清空上方的台語音標儲存格 + sheet.range((row - 1, col)).value = None + + # 清空下方的台語注音符號儲存格 + sheet.range((row + 1, col)).value = None + + # 每處理 15 個字元後,換到下一行 + row += 4 + + # 逐行處理資料,從 Row 3 開始,每列處理 15 個字元 + row = 3 + for i in range(total_rows_needed): + for col in range(4, 19): # 【D欄=4】到【R欄=18】 + cell_value = sheet.range((row, col)).value # 取得 D4, E4, ..., R4 的內容 + + # 確認內容不為空 + if cell_value: + # 分割字串來提取羅馬拼音和台語注音 + lo_ma_ji = cell_value.split('〔')[1].split('〕')[0] # 取得〔羅馬拼音〕 + zu_im_hu_ho = cell_value.split('【')[1].split('】')[0] # 取得【台語注音】 + + # 將羅馬拼音填入當前 row + 1 的儲存格 + sheet.range((row + 1, col)).value = lo_ma_ji + + # 將台語注音填入當前 row + 3 的儲存格 + sheet.range((row + 3, col)).value = zu_im_hu_ho + + # 每處理 15 個字元後,換到下一行 + row += 4 + + print("已完成【台語音標】和【台語注音符號】標註工作。") + + # 保存 Excel 檔案 + wb.save('Tai_Gi_Zu_Im_Bun.xlsx') + # wb.close() + + # 令人工手動填入的台語音標和注音符號不要顯示 + + # 選擇名為 "顯示注音輸入" 的命名範圍 + named_range = wb.names['顯示注音輸入'] + + named_range.refers_to_range.value = False \ No newline at end of file diff --git a/p730_Tng_Sing_Bang_Iah.py b/p730_Tng_Sing_Bang_Iah.py index 9331367..7aebdd2 100644 --- a/p730_Tng_Sing_Bang_Iah.py +++ b/p730_Tng_Sing_Bang_Iah.py @@ -119,15 +119,16 @@ def build_web_page(wb, sheet, total_length): # ========================================================= # 將已注音之漢字加入【漢字注音表】 # ========================================================= - ruby_tag = f""" - - {han_ji} - {lo_ma_im_piau} - ( - {zu_im_hu_ho} - ) - - """ + # ruby_tag = f""" + # + # {han_ji} + # {lo_ma_im_piau} + # ( + # {zu_im_hu_ho} + # ) + # + # """ + ruby_tag = f"{han_ji}{lo_ma_im_piau}{zu_im_hu_ho}" write_buffer += (ruby_tag + "\n") index += 1