post

PyPtt.API.post(self, board: str, title_index: int, title: str, content: str, sign_file: [str | int] = 0, anonymous: bool = False, display_id: str | None = None) None

發文。

參數:
  • board (str) -- 看板名稱。

  • title_index (int) -- 文章標題編號。

  • title (str) -- 文章標題。

  • content (str) -- 文章內容。

  • sign_file (str | int) -- 編號或隨機簽名檔 (x),預設為 0 (不選)。

  • anonymous (bool) -- 是否匿名發文,預設為 False。僅在該看板本身具有匿名 (BRD_ANONYMOUS) 屬性時才會生效,一般看板無法透過此參數強制匿名;PyPtt 只能在該提示出現時回覆它。

  • display_id (str) -- 匿名發文時欲顯示的自訂名稱;預設為 None,代表使用 pttbbs 預設值 (預設匿名板為 "Anonymous.",否則為原 ID)。pttbbs 會在暱名 (含預設的 "Anonymous") 後方加上一個 "."(例如 display_id='Fox' 會顯示為 "Fox."),此為 pttbbs 固定行為, 無法調整。僅能在 anonymous=True 時使用。

回傳:

None

引發:

範例:

import PyPtt

ptt_bot = PyPtt.API()
try:
    # .. login ..
    ptt_bot.post(board='Test', title_index=1, title='PyPtt 程式貼文測試', content='測試內容', sign_file=0)
    # 匿名發文 (需看板本身具有匿名屬性)
    ptt_bot.post(board='AnonBoard', title_index=1, title='匿名貼文測試', content='測試內容',
                 sign_file=0, anonymous=True)
    # 匿名發文並自訂顯示名稱
    ptt_bot.post(board='AnonBoard', title_index=1, title='匿名貼文測試', content='測試內容',
                 sign_file=0, anonymous=True, display_id='Fox')
    # .. do something ..
finally:
    ptt_bot.logout()