Automate Posting from Reddit to Instagram
Ever found yourself endlessly scrolling through Reddit, thinking “this would be perfect for my Instagram”? I sure did! That’s why I built AutoPostBot - my personal content assistant that finds viral Reddit videos and posts them to Instagram automatically. Let me show you how it works and how you can build one too!
As someone managing social media accounts, I faced a common challenge:
I wanted to focus on engagement and strategy, not the repetitive grunt work. So I automated it!
The system follows a simple workflow:
All of this happens automatically on a schedule!
def get_reddit_videos(sub_reddits, num_top_posts=3):
# Connect to Reddit API
reddit = praw.Reddit(
client_id=os.environ.get("REDDIT_CLIENT_ID"),
client_secret=os.environ.get("REDDIT_CLIENT_SECRET"),
user_agent=os.environ.get("REDDIT_USER_AGENT"),
)
# Collect video posts
video_posts = []
for subreddit_name in sub_reddits:
subreddit = reddit.subreddit(subreddit_name)
top_posts = subreddit.top(limit=num_top_posts, time_filter='day')
# Filter for videos only
for post in top_posts:
if post.is_video and not post.over_18:
video_posts.append({
"title": post.title,
"url": post.url,
"subreddit": subreddit_name,
"score": post.score,
})
# Sort by popularity
return sorted(video_posts, key=lambda x: x["score"], reverse=True)
The coolest part? The bot uses AI to generate relevant hashtags based on the content:
def generate_instagram_tags(subreddit, posttitle):
prompt = f"""You are an Instagram expert. Generate a list of 10 relevant
and trending hashtags for the following Reddit post that will be uploaded to Instagram.
Subreddit: {subreddit}
post title: {posttitle}
Only return the hashtags as a space-separated list. Do not include explanations."""
# Using OpenAI's GPT-4o
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "developer", "content": "Talk like a pirate."},
{"role": "user", "content": prompt},
],
)
return response.choices[0].message['content'].strip()
I even added a fun “Talk like a pirate” system message to get more creative hashtags! 🏴☠️
Want to build your own? Here’s how:
Clone the repo and install dependencies:
git clone https://github.com/yourusername/AutoPostBot.git
cd AutoPostBot
pip install -r requirements.txt
Set up your environment variables in a .env
file:
REDDIT_CLIENT_ID='your_reddit_client_id'
REDDIT_CLIENT_SECRET='your_reddit_client_secret'
REDDIT_USER_AGENT='your_app_name'
INSTA_USER_USERNAME='your_instagram_username'
INSTA_USER_PASSWORD='your_instagram_password'
REDDIT_MAX_POSTS=1
OPENAI_API_KEY='your_openai_api_key'
Run it manually to test:
python main.py
Schedule it to run daily using cron, Task Scheduler, or a cloud service
While I built this for fun, there are serious applications:
Since implementing AutoPostBot:
Building AutoPostBot taught me that even creative tasks can benefit from automation. By letting the bot handle the repetitive parts, I can focus on strategy and engagement.
The best part? It’s completely customizable. You can add more subreddits, change the filtering criteria, or even modify the AI prompt to match your brand voice.
So, what will you automate next? 🚀