Skip to content

Instantly share code, notes, and snippets.

@13steinj
Created November 28, 2015 22:10
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 13steinj/784c4889d2483f51f6df to your computer and use it in GitHub Desktop.
Save 13steinj/784c4889d2483f51f6df to your computer and use it in GitHub Desktop.
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