-
Notifications
You must be signed in to change notification settings - Fork 91
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
取得 big5-uao 編碼的文章/信件內容 #11
Comments
UAO encoder/decoder: |
!
感恩 |
Big5uao.py 有幾個問題︰
另外,uao 使用的字碼表去除了 "\uFFFD",所以無法編碼的字元會丟出例外而非被替換成替代字元︰ >>> import uao
>>> uao.register_uao()
>>> "나는".encode("big5-uao")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "d:\dev\pyuao\uao\__init__.py", line 15, in encode
result = b"".join(self._encode(input, errors))
File "d:\dev\pyuao\uao\__init__.py", line 33, in _encode
c_replaced, next_i = lookup_error(errors)(err)
UnicodeEncodeError: 'big5-uao' codec can't encode character '\ub098' in position
0: illegal multibyte sequence Big5uao.py: >>> from PTTLibrary import Big5uao
>>> "나는".encode("Big5uao")
b'\xff\xfd\xff\xfd' |
好,我改用 uao 專案試試看。 謝謝你的幫助。 |
我思考了一下,是不是 MailInformation 裡面多一個欄位放 RAW 資料就好了? |
不是。因為 PTTLibrary 登入時使用 下面是擷圖比較 bbs 和 bbsu 的畫面 (pietty)︰ 可以看到 LOGO 的 "P", "1", "8" 都有顏色錯誤的情況,這是由於雙色字無法用 utf-8 編碼。這在普通文章中沒什麼問題,因為很少用到上色甚至雙色字;但對於 ANSI Art 卻是致命的(參考 asciiart 板)。 後來我有實作了一個非常簡易的 PTTBot(沒有 threading、沒有自動重連線、很多情況都沒測試、只會進信箱和擷取文章),使用 big5-uao 連線︰ |
我使用 PTTChrome 看起來顯示雙色沒有問題,我看了一下 PTTChrome 的程式碼,裡面也有 UTF8 與 Big5uao 的轉換。 詳見 見此討論,問題似乎沒有很簡單, 另外我也看了 pcman 專案, 歷史這麼悠久的專案在 2017 年,依舊有類似的問題存在。 所以總結兩條路可以選,
我不太建議走不安全的選項二,另外 UTF-8 屬於 Unicode 的一種變型,可以把任何編碼轉換至 UTF-8, https://zh.wikipedia.org/wiki/UTF-8 我會繼續看有沒有方案一的候選,感謝您的回報。 |
這項的原因是?如果是為了連線時能取得以 big5-uao 編碼的資料,ssh 也可以做到。只要做以下修改︰ diff --git a/PTTLibrary/PTT.py b/PTTLibrary/PTT.py
index 22a0457..d7fd041 100644
--- a/PTTLibrary/PTT.py
+++ b/PTTLibrary/PTT.py
@@ -414,7 +414,7 @@ class Library(object):
# self.__ConnectList[ConnectIndex].load_system_host_keys()
# self.__ConnectList[ConnectIndex].set_missing_host_key_policy(paramiko.WarningPolicy())
self.__ConnectList[ConnectIndex].set_missing_host_key_policy(paramiko.AutoAddPolicy())
- self.__ConnectList[ConnectIndex].connect('ptt.cc', username = 'bbsu', password = '', pkey = self.__SSHKey)
+ self.__ConnectList[ConnectIndex].connect('ptt.cc', username = 'bbs', password = '', pkey = self.__SSHKey)
self.__ConnectList[ConnectIndex].channel = self.__ConnectList[ConnectIndex].invoke_shell(width = self.width, height = self.height)
except paramiko.AuthenticationException:
|
簡單來說就 |
喔! 原來是這樣,好 我在想一下架構怎麼調整比較好。 謝謝各位啦。 |
@eight04 你改成 bbs 執行登入功能可以成功嗎? |
不行。有幾個問題︰
ptt-mail-backup 使用的方法,是把資料丟給 pyte,pyte 會解析色碼並把字元包含顏色畫到 80x24 大小的 buffer 上。然後 ptt-mail-backup 再從 buffer 中取出字元內容,進行 decode。 P.S. 目前 pyte 不支援閃爍字,所以原始資料中有閃爍的 ANSI escape code ( |
已經成功取得原始資料,使用 big5 寫入檔案後,可使用 big5 正確顯示,此問題結束後推上 pypi。 |
我測試了 master,可以正常抓取資料 🎉 其它和 ANSI 文章相關的問題,我開了新的 issue。 |
在 utf-8 模式下,雙色字無法被正確上色。希望能新增一個選項,用來取得 big5 編碼下的原始資料。類似︰
The text was updated successfully, but these errors were encountered: