Skip to content

Instantly share code, notes, and snippets.

@sidward35
Created September 25, 2021 10:23
Show Gist options
  • Save sidward35/f0d31ba0d2e47830eba8790f51f40a33 to your computer and use it in GitHub Desktop.
Save sidward35/f0d31ba0d2e47830eba8790f51f40a33 to your computer and use it in GitHub Desktop.
Post images to Reddit and add a comment
import praw
from datetime import date
def postFig(img_name, sub, flair=''):
creds = {
"client_id":"",
"client_secret":"",
"user_agent":"script by u/username",
"redirect_uri":"http://localhost:8080",
"refresh_token":""
}
reddit = praw.Reddit(client_id=creds['client_id'], client_secret=creds['client_secret'], user_agent=creds['user_agent'], redirect_uri=creds['redirect_uri'], refresh_token=creds['refresh_token'])
subreddit = reddit.subreddit(sub)
curr_date = str(date.today().strftime("%d %b %Y")).upper().replace(' ','')
title = ''+curr_date
if len(flair)>0:
for template in subreddit.flair.link_templates:
if template['text']==flair:
id = template['id']
post = subreddit.submit_image(title,image_path=img_name,flair_id=id,flair_text=flair)
else:
post = subreddit.submit_image(title,image_path=img_name)
post.reply('Source: [source name](https://www.example.com)')
img_name = 'newplot.png'
postFig(img_name, 'stockmarket', 'Recap/Watchlist')
@sidward35
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment