ustclug / blogs

USTCLUG 同学们的博客列表
66 stars 13 forks source link

OPML via CI #5

Closed liyishuai closed 1 year ago

liyishuai commented 5 years ago

Build: tuna/blogroll#11 Validate: tuna/blogroll#50

taoky commented 1 year ago

糊了一个生成脚本 https://github.com/ustclug/blogs/blob/master/opml.py

libreliu commented 1 year ago

糊了一个生成脚本 https://github.com/ustclug/blogs/blob/master/opml.py

我用的 Thunderbird 102.6.1 (Windows 10),似乎生成的 OPML 文件并不能成功导入 Thunderbird (会提示“文件 opml.opml 似乎不是一个有效的 OPML 文件。”)

另外,在 Windows (& cp936)下默认字符编码是 gbk,可能最好在 open 那里指定一下

diff --git a/opml.py b/opml.py
index e85f368..6309d85 100644
--- a/opml.py
+++ b/opml.py
@@ -17,7 +17,7 @@ def check(rssurl):
 def main(args):
     contents = []
     # 1. Parse README.md and get the list of links
-    with open("./README.md") as f:
+    with open("./README.md", encoding="utf-8") as f:
         for line in f:
             if line.startswith("|"):
                 try:
taoky commented 1 year ago

Thunderbird 导入不了的原因是 Windows 下 python opml.py --thunderbird > opml.opml 得到的 opml.opml 是 UTF-16 的文件,但是 Thunderbird(至少在 Linux 下)只吃 UTF-8。

open() 的 encoding 已经在 https://github.com/ustclug/blogs/commit/898f53779c69b87dc78d1da9efb131eabc26ac75 加了。

taoky commented 1 year ago

加上了 sys.stdout.reconfigure(encoding='utf-8') 之后,Python 在 Windows console 下文件重定向的行为是:

所以还是只能把脚本改成默认输出文件了。

taoky commented 1 year ago

https://github.com/ustclug/blogs/commit/5acf240143c94735d35c40af18df7db958d6fb3c

@libreliu

libreliu commented 1 year ago

5acf240

@libreliu

现在在 Windows 10 + cp936 下面可以啦,感谢