Skip to content

Commit

Permalink
改善 a801 的輸入介面;強化查外不到的例外處理。
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Nov 2, 2024
1 parent 8cdf3dd commit f5007e6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
4 changes: 1 addition & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"program": "a801_十五音切讀音.py",
"console": "integratedTerminal",
"args": [
"",
"",
""
"君五求"
]
},
{
Expand Down
10 changes: 8 additions & 2 deletions a800_漢字查十五音標音.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
sys.exit(-1)

# 取得使用者之輸入:欲查詢讀音的漢字
beh_cha_e_han_ji = sys.argv[1]
beh_ca_e_han_ji = sys.argv[1]

# 建立資料庫連線
connection = sqlite3.connect('雅俗通十五音字典.db')
cursor = connection.cursor()

han_ji_piau_im = han_ji_ca_piau_im(cursor, beh_cha_e_han_ji)
han_ji_piau_im = han_ji_ca_piau_im(cursor, beh_ca_e_han_ji)

# 檢查是否查找到結果
if not han_ji_piau_im:
print("查找不到漢字:【{beh_ca_e_han_ji}】。")
connection.close()
sys.exit(-1)

os.system('cls')
for record in han_ji_piau_im:
Expand Down
53 changes: 33 additions & 20 deletions a801_十五音切讀音.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@

if __name__ == "__main__":
# 確認使用者有輸入反切之切語參數
if len(sys.argv) != 4:
print("請輸入欲查詢讀音之【字韻】、【調號】、【切音】,如:君 五 求!")
if len(sys.argv) != 2:
print("請輸入欲查詢讀音之【切語】,如:君五求!")
sys.exit(-1)

# 取得使用者之輸入:欲查詢讀音的漢字
字韻 = sys.argv[1]
調號 = sys.argv[2]
切音 = sys.argv[3]
切語 = sys.argv[1]

# 檢查輸入是否為 3 個字元
if len(切語) != 3:
print("輸入格式錯誤!請輸入 3 個字元的【字韻】【調號】【切音】,如:君五求!")
sys.exit(-1)

# 將切語拆分為 字韻、調號 和 切音
字韻 = 切語[0]
調號 = 切語[1]
切音 = 切語[2]

# 建立資料庫連線
connection = sqlite3.connect('雅俗通十五音字典.db')
Expand All @@ -25,22 +33,27 @@
聲調 = tiau_ho_tng_siann_tiau(調號)
han_ji_piau_im = huan_ciat_ca_piau_im(cursor, 字韻, 聲調, 切音)

# 檢查是否查找到結果
if not han_ji_piau_im:
print("查無結果,請確認輸入是否正確。")
connection.close()
sys.exit(-1)

os.system('cls')
for record in han_ji_piau_im:
上字 = record['切音']
下字 = record['字韻']
漢字 = record['漢字']
雅俗通標音 = record['雅俗通標音']
十五音標音 = record['十五音標音']
台語音標 = record['漢字標音']

# 顯示結果
print('\n=======================================')
# print(f'查詢切音:【{字韻}】【{調號}】【{切音}】')
print(f'查詢切音:【{字韻}{調號}{切音}】')
print(f'漢字:{漢字} [{台語音標}]')
# print(f'十五音切音:{十五音標音} (雅俗通切音:{雅俗通標音})')
print(f'十五音:{十五音標音} (雅俗通:{雅俗通標音})')
# 顯示結果
上字 = han_ji_piau_im[0]['切音']
下字 = han_ji_piau_im[0]['字韻']
台語音標 = han_ji_piau_im[0]['漢字標音']
雅俗通標音 = han_ji_piau_im[0]['雅俗通標音']
十五音標音 = han_ji_piau_im[0]['十五音標音']
print('\n=======================================')
print(f'查詢切音:【{字韻}{調號}{切音}】')
print(f'台語音標:{台語音標}')
print(f'十五音切語:{十五音標音}(雅俗通:{雅俗通標音})')

# 將所有漢字連接成同一個字串,並使用 "、" 分隔
漢字列表 = "、".join(record['漢字'] for record in han_ji_piau_im)
print(f'漢字:{漢字列表}')

# 關閉資料庫連線
connection.close()

0 comments on commit f5007e6

Please sign in to comment.