Skip to main content

API Reference

This section details the core APIs and functions of RedHarmony.

Content Generation API

openAI_generate(prompt, max_tokens=150)

Located in utils/constant.py

Generates content using GPT-4 based on provided prompts.

from utils.constant import openAI_generate

# Example usage
content = openAI_generate(
prompt="Create an engaging post about Python programming",
max_tokens=200
)

generate_post_content(prompt, subreddit, max_tokens=200)

Generates post content for a specific subreddit.

content = generate_post_content(
prompt="You are a Python expert...",
subreddit="python",
max_tokens=200
)

generate_post_title(post_content, max_tokens=50)

Creates an appropriate title for post content.

title = generate_post_title(post_content, max_tokens=50)

Database API

initialize_db()

Located in utils/database.py

Initializes the SQLite database with required tables.

from utils.database import initialize_db

success = initialize_db()

save_post(post_id, username, subreddit, title)

Saves post information to the database.

from utils.helper import save_post

save_post(
post_id="abc123",
username="user123",
subreddit="python",
title="My Python Post"
)

save_comment(username, comment_id, post_id)

Saves comment information to the database.

from utils.helper import save_comment

save_comment(
username="user123",
comment_id="xyz789",
post_id="abc123"
)

Reddit Interaction API

get_reddit_client(account)

Creates an authenticated Reddit client instance.

from utils.helper import get_reddit_client

reddit = get_reddit_client(account_config)

create_post(reddit, username, subreddit_name, title, content)

Creates a new Reddit post.

from utils.post import create_post

create_post(
reddit=reddit_client,
username="user123",
subreddit_name="python",
title="Post Title",
content="Post Content"
)

create_comment(submission, content, username, post_id)

Creates a comment on a Reddit post.

from utils.comment import create_comment

create_comment(
submission=post,
content="Comment content",
username="user123",
post_id="abc123"
)

Utility Functions

load_accounts(filepath="accounts.json")

Loads persona configurations from JSON file.

from utils.helper import load_accounts

accounts = load_accounts()

subreddit_valid(reddit, subreddit)

Validates if a subreddit exists and is accessible.

from utils.helper import subreddit_valid

is_valid = subreddit_valid(reddit_client, "python")

get_flairs(reddit, subreddit_name)

Retrieves available post flairs for a subreddit.

from utils.helper import get_flairs

flairs = get_flairs(reddit_client, "python")