Skip to content

louislouist/postreddit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postreddit

Some typescript helper functions for posting to reddit using snoowrap with Promise type modifications. Probably unsafe.

Setup

Create a .env file in the root of your project with:

USER_AGENT=YourAppName/1.0.0 by YourRedditUsername
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
REDDIT_USERNAME=your_reddit_username
REDDIT_PASSWORD=your_reddit_password

These values are obtained by creating a Reddit App at https://www.reddit.com/prefs/apps

fun

await RedditPoster.postText('test', 'Hello Reddit', 'This is my first post!');

await RedditPoster.postLink('test', 'Check this out', 'https://example.com');

await RedditPoster.commentOnPost('abc123', 'Nice post!');

const postId = extractPostId('https://www.reddit.com/r/test/comments/abc123/example_post/');
console.log(postId); // "abc123"

Each method logs the success to the console with the post or comment URL. Errors are caught and logged with a helpful message.

npm install

npm install git+http://github.com/louislouist/postreddit.git

cd node_modules/postreddit

npm run build

example code

import { RedditPoster, extractPostId } from 'postreddit';

async function main() {
	const postUrl = await RedditPoster.postText('test', 'Test B', 'Please work.');

	if (postUrl) {
		const postId = extractPostId(postUrl);
		console.log(postUrl);

		if (postId) {
			await RedditPoster.commentOnPost(postId, 'Thanks for all the fish!');
			console.log(postId);
		}
	}
}

main();

About

library to post items for 77sq to reddit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors