Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def main(username, password, limit=None):
"""redditsaver
Usage: in a cmd/terminal, type python3 or py -3 depending on your OS
in the folder that you want stuff to be saved into, and place this file there too.
you must install praw beforehand (pip3 install praw)
then type "import redditsaver" without qoutes.
then type "redditsaver.main('your username', 'yourpass')" without the double qoutes
then wait, and you are done.
"""
import praw
if username.startswith('/u/'):
username = username[3:]
elif username.startswith('u/'):
username = username[2:]
r = praw.Reddit('/u/{0} saving all of his/her saved posts to his harddrive'.format(username))
r.login(username, password, disable_warning=True)
count = 0
for Thing in r.user.get_saved(limit=limit):
count += 1
message = ""
if hasattr(Thing, 'selftext'):
f = open("#{0} -- post -- {1}".format(count, Thing.id), 'w')
message += Thing.title + '\n'
message += "by /u/{0}".format(Thing.author.name) if getattr(Thing.author, 'name') else 'by [deleted]'
message += '\n\n' + Thing.permalink + '\n\n'
if getattr(Thing, 'selftext'):
message += Thing.selftext + '\n\n'
else:
message += Thing.url + '\n\n'
else:
f = open("#{0} -- comment -- {1}".format(count, Thing.id), 'w')
message += "by /u/{0}".format(Thing.author.name) if getattr(Thing.author, 'name') else 'by [deleted]'
message += '\n\n' + Thing.permalink + '\n\n'
message += Thing.body + '\n\n'
f.write(message)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.