API reference

async libpttea.api.login(account: str, password: str, del_duplicate=True, del_error_log=True, timeout_delay=0) API

Log in to PTT.

登入 PTT

Parameters:
  • account (str) – The PTT account username.

  • password (str) – The PTT account password.

  • del_duplicate (bool, default True) – Flag that let PTT to delete duplicate login sessions if they exist.

  • del_error_log (bool, default True) – Flag that let PTT to clear error logs on login.

  • timeout_delay (int, default 0) – For user-defined additional timeout

Returns:

API – An instance of the API class.

Return an instance of the API object.


class libpttea.api.API
async login(account: str, password: str, del_duplicate=True, del_error_log=True, timeout_delay=0) None

Log in to PTT.

登入 PTT

Parameters:
  • account (str) – The PTT account username.

  • password (str) – The PTT account password.

  • del_duplicate (bool, default True) – Flag that let PTT to delete duplicate login sessions if they exist.

  • del_error_log (bool, default True) – Flag that let PTT to clear error logs on login.

  • timeout_delay (int, default 0) – For user-defined additional timeout

async logout(force=False) None

Log out from PTT.

登出 PTT

Parameters:

force (bool, default False) – If force is true, ignore the TimeoutError.

async get_system_info() list[str]

Get the PTT system info.

查看 PTT 系統資訊

Returns:

list[str] – Return a list of strings that contains the PTT system information.

async get_favorite_list() list[dict]

Get the favorite list.

取得 “我的最愛” 清單

Returns:

list[dict] – Return a list of dict that contains favorite items.

  • favorite items , dict like

    {‘index’: ‘’, ‘board’: ‘’, ‘type’: ‘’, ‘describe’: ‘’, ‘popularity’: ‘’, ‘moderator’: ‘’}

async get_latest_post_index(board: str) int

Get the latest post index.

取得最新的文章編號

Parameters:

board (str) – The PTT board name.

Returns:

int – Return the latest post index in a specific board.

async get_post_list(board: str, start: int, stop: int) list[dict]

Get the post list by range; the start < stop is required.

取得範圍內的文章列表

Parameters:
  • board (str) – The PTT board name.

  • start (int) – The starting index of the post range (inclusive).

  • stop (int) – The ending index of the post range (inclusive).

Returns:

list[dict] – Return a list of dict that contains post info.

  • post item , dict like

    {‘index’: ‘’, ‘label’: ‘’, ‘count’: ‘’, ‘date’: ‘’, ‘author’: ‘’, ‘title’: ‘’}

async get_post(board: str, index: int) AsyncGenerator[tuple[list, list]]

Get the post data.

取得文章資料

Parameters:
  • board (str) – The PTT board name.

  • index (int) – The post index.

Returns:

AsyncGenerator[tuple[list, list]] – return an Asynchronous Generator that yields post data as a tuple(contents_html, post_replies)

-contents_html:

list of html string.

-post_replies:
list of dict that contains reply , dict like

{‘type’: ‘’, ‘author’: ‘’, ‘reply’: ‘’, ‘ip’: ‘’, ‘datetime’: ‘’}