Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the url from Submission object in PRAW?

Tags:

python

praw

I'm using PRAW to create a Reddit bot that submits something once a day. After submitting I want to save the url of the submission and write it to a text file.

url = r.submit(subreddit, submission_title, text=submission_text)

The above returns a Submission object, but I want the actual url. Is there a way to get the url from a Submission object, or do I need to do something else to get the url?

like image 830
vwos Avatar asked Oct 07 '15 15:10

vwos


1 Answers

submission.shortlink (previously .short_link) is what you're looking for, if submission.permalink wasn't good enough.

reddit = praw.Reddit("Amos")
submission = reddit.get_submission(submission_id="XYZ")
print submission.permalink
>>> www.reddit.com/r/subreddit/comments/XYZ
like image 183
TankorSmash Avatar answered Nov 15 '22 03:11

TankorSmash