{"id":17886646,"url":"https://github.com/holzmaster/node-pr0gramm-api","last_synced_at":"2025-03-22T14:31:44.216Z","repository":{"id":47599828,"uuid":"72929534","full_name":"holzmaster/node-pr0gramm-api","owner":"holzmaster","description":"Node.js pr0gramm API","archived":false,"fork":false,"pushed_at":"2025-03-01T20:58:50.000Z","size":598,"stargazers_count":20,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T07:37:51.875Z","etag":null,"topics":["hacktoberfest","nodejs","pr0gramm","pr0gramm-api","pr0gramm-com","typescript"],"latest_commit_sha":null,"homepage":"https://holzmaster.github.io/node-pr0gramm-api","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/holzmaster.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-05T13:59:59.000Z","updated_at":"2025-02-02T02:13:08.000Z","dependencies_parsed_at":"2023-02-17T11:45:49.767Z","dependency_job_id":"555f4073-845f-438a-9a39-41281644c56b","html_url":"https://github.com/holzmaster/node-pr0gramm-api","commit_stats":{"total_commits":207,"total_committers":7,"mean_commits":"29.571428571428573","dds":0.09661835748792269,"last_synced_commit":"1a99cab497afe053c5165901aecf05d846ee3764"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holzmaster%2Fnode-pr0gramm-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holzmaster%2Fnode-pr0gramm-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holzmaster%2Fnode-pr0gramm-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holzmaster%2Fnode-pr0gramm-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/holzmaster","download_url":"https://codeload.github.com/holzmaster/node-pr0gramm-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244972194,"owners_count":20540940,"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":["hacktoberfest","nodejs","pr0gramm","pr0gramm-api","pr0gramm-com","typescript"],"created_at":"2024-10-28T13:08:41.572Z","updated_at":"2025-03-22T14:31:43.927Z","avatar_url":"https://github.com/holzmaster.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pr0gramm-api [![Build Status](https://travis-ci.com/holzmaster/node-pr0gramm-api.svg?branch=master)](https://travis-ci.com/holzmaster/node-pr0gramm-api)\nA Node.js API for pr0gramm written in TypeScript.\n```Shell\nnpm install -S pr0gramm-api\n```\n\n## Usage\nLogin with username/password:\n```ts\nimport { Pr0grammAPI, NodeRequester, ItemFlags } from \"pr0gramm-api\";\n\nmain();\nasync function main() {\n    const requester = NodeRequester.create();\n    // When using this library in the browser, use this requester:\n    // const requester = BrowserRequester.create();\n\n    const api = Pr0grammAPI.create(requester);\n\n    const mainItems = await api.items.getItems({\n        promoted: true,\n        flags: ItemFlags.SFW\n    });\n\n    console.log(mainItems.items);\n\n    const captchaData = await api.user.requestCaptcha();\n    // captchaData.captcha contains the image as a data URI\n\n    const loginResponse = await api.user.login(\"cha0s\", \"stahl0fen80\", captchaData.token, \"aaaaa\");\n    if(!loginResponse.success) {\n        console.log(\"Could not log in :(\");\n        if(loginResponse.ban !== null) {\n            console.log(\"You are banned. Reason:\");\n            console.log(loginResponse.ban.reason);\n            return;\n        }\n    }\n}\n```\n\nLogin with oAuth:\n```ts\nimport * as readline from \"node:readline/promises\";\nimport { AuthorizationCode } from \"simple-oauth2\";\nimport { Pr0grammAPI, NodeRequester, ItemFlags } from \"pr0gramm-api\";\n\nconst oAuthAccessCodeClient = new AuthorizationCode({\n    client: {\n        // See above\n        id: \"\u003cclient_id\u003e\",\n        secret: \"\u003cclient_secret\u003e\",\n    },\n    auth: {\n        tokenHost: \"https://pr0gramm.com/\",\n        tokenPath: \"/api/oauth/createAccessToken\",\n        authorizePath: \"/oauth/authorize\",\n    }\n});\n\nmain();\nasync function main() {\n    const authorizationUri = oAuthAccessCodeClient.authorizeURL({\n        redirect_uri: authCallbackUrl,\n        scope: \"items.get\",\n        state: \"\u003cstate\u003e\",\n    });\n\n    console.log(\"Go to this URL and enter the auth code from ?code=\u003cauth code\u003e from the callback URL:\");\n    console.log(authorizationUri);\n\n    const rl = readline.createInterface({\n        input: process.stdin,\n        output: process.stdin,\n    });\n    const authCode = await rl.question(\"Auth-Code: \");\n    rl.close();\n\n    const tokenHandler = await oAuthAccessCodeClient.getToken({\n        code: authCode,\n    });\n\n    const requester = NodeRequester.create();\n    requester.setOAuthAccessToken(tokenHandler.token.access_token);\n\n    const api = Pr0grammAPI.create(requester);\n\n    const mainItems = await api.items.getItems({\n        promoted: true,\n        flags: ItemFlags.All\n    });\n\n    console.log(mainItems.items);\n}\n```\n\n\n### Stream Walker\nThe item stream requires you to call the next page of elements. Because it is a common operation to just walk over all items in the stream, there is a stream walker api for convenience:\n```TypeScript\nimport { Pr0grammAPI, NodeRequester, ItemFlags } from \"pr0gramm-api\";\n\nmain();\nasync function main() {\n    const api = Pr0grammAPI.create(NodeRequester.create());\n\n    // Create a walker that iterates through the entire stream of elements\n    // starting at item 0, going upwards\n    const itemStream = api.items.walkStreamNewer({\n        newer: 0,\n        flags: ItemFlags.SFW,\n        promoted: false,\n    });\n\n    // Asynchronous iteration over all items on pr0gramm\n    // automatically requests next items\n    for await (const item of itemStream) {\n        console.log(item.id + \": \" + item.user);\n    }\n}\n```\n*Important*:\n- This approach uses async generators, which are currently hidden behind node's `--harmony` flag. To use this API, you need to start node with `--harmony`.\n- If you are using TypeScript, you need to have `\"esnext.asynciterable\"` and `\"es6\"` in your `lib` entry in `tsconfig.json`.\n- The module is exposed as CommonJS, not (yet) ES modules. If you use plain JavaScript, keep in mind using CommonJS imports instead of ES imports: `const { Pr0grammAPI, ItemFlags } = require(\"pr0gramm-api\");`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholzmaster%2Fnode-pr0gramm-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fholzmaster%2Fnode-pr0gramm-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholzmaster%2Fnode-pr0gramm-api/lists"}