{"id":22355450,"url":"https://github.com/kevinptt0323/ptt-client","last_synced_at":"2025-07-30T10:31:46.408Z","repository":{"id":24943660,"uuid":"94242065","full_name":"kevinptt0323/ptt-client","owner":"kevinptt0323","description":"A Node.js/Browser client for fetching data from ptt.cc","archived":false,"fork":false,"pushed_at":"2023-01-06T01:46:22.000Z","size":687,"stargazers_count":81,"open_issues_count":10,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-08T08:27:09.365Z","etag":null,"topics":["javascript","npm-package","ptt","typescript","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinptt0323.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-13T17:58:39.000Z","updated_at":"2024-10-03T13:27:44.000Z","dependencies_parsed_at":"2023-01-14T01:52:09.604Z","dependency_job_id":null,"html_url":"https://github.com/kevinptt0323/ptt-client","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinptt0323%2Fptt-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinptt0323%2Fptt-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinptt0323%2Fptt-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinptt0323%2Fptt-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinptt0323","download_url":"https://codeload.github.com/kevinptt0323/ptt-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228124671,"owners_count":17873170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","npm-package","ptt","typescript","websocket"],"created_at":"2024-12-04T14:06:33.081Z","updated_at":"2024-12-04T14:06:34.017Z","avatar_url":"https://github.com/kevinptt0323.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ptt-client\n**ptt-client** is an unofficial client to fetch data from PTT ([ptt.cc]), the\nfamous BBS in Taiwan, over WebSocket. This module works in browser and Node.js.\n\nPTT supports connection with WebSocket by [official].\n\n[ptt.cc]: https://www.ptt.cc\n[official]: https://www.ptt.cc/bbs/SYSOP/M.1496571808.A.608.html\n\n## Installation\n```\nnpm install ptt-client\n```\n\n## Example\n```js\nimport Ptt from 'ptt-client';\nimport {Article, Board, Mail} from 'ptt-client/sites/ptt/model';\n\n// if you are using this module in node.js, 'ws' is required as WebSocket polyfill.\n// you don't need this in modern browsers\nglobal.WebSocket = require('ws');\n\n(async function() {\n  const ptt = new Ptt();\n\n  ptt.once('connect', () =\u003e {\n\n    const kickOther = true;\n    if (!await ptt.login('username', 'password', kickOther))\n      return;\n  \n    // get last 20 articles from specific board. the first one is the latest\n    let query = ptt.select(Article).where('boardname', 'C_Chat');\n    let article = await query.get();\n\n    // get articles with offset \n    let offset = articles[article.length-1].id - 1;\n    query.where('id', offset);\n    let articles2 = await query.get();\n\n    // get articles with search filter (type: 'push', 'author', 'title')\n    query = ptt.select(Article)\n      .where('boardname', 'C_Chat')\n      .where('title', '閒聊')\n      .where('title', '京阿尼')\n      .where('push', '20');\n    articles = await query.get();\n  \n    // get the content of specific article\n    query.where('id', articles[articles.length-1].id);\n    let article = await query.getOne();\n\n    // get board list\n    query = ptt.select(Board).where('entry', 'class');\n    let classBoards = await query.get();\n\n    // get hot board list\n    query = ptt.select(Board).where('entry', 'hot');\n    let hotBoards = await query.get();\n  \n    // get your favorite list\n    query = ptt.select(Board).where('entry', 'favorite');\n    let favorites = await query.get();\n\n    // search board by prefix\n    query = ptt.select(Board).where('prefix', 'c_cha');\n    let boards = await query.get();\n  \n    // get favorite list in a folder\n    if (favorites[0].folder) {\n      query.where('offsets', [favorites[0].id]);\n      let favorites2 = await query.get();\n    }\n\n    // get mails\n    query = ptt.select(Mail);\n    let mails = await query.get();\n\n    // get mail\n    query.where('id', mails[0].sn);\n    let mail = await query.getOne();\n\n    await ptt.logout();\n\n  });\n})();\n```\n\n## Development\n```\nnpm run test\nnpm run build\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinptt0323%2Fptt-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinptt0323%2Fptt-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinptt0323%2Fptt-client/lists"}