Created
June 6, 2014 20:26
-
-
Save macieksk/95ce64d53e29990ecdf8 to your computer and use it in GitHub Desktop.
Download csv, json with your reddit saved links.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import praw | |
import getpass | |
import json | |
import csv | |
uname="yourusername" | |
fbase="reddit_saved" | |
print("Connecting reddit...") | |
r= praw.Reddit("getting saved links") | |
r.login(username=uname,password=getpass.getpass()) | |
print("Downloading saved posts...") | |
rsaved=list(r.user.get_saved(limit=None)) | |
print("Got {} posts. Downloading additional info...".format(len(rsaved)) ) | |
saved=[(l.subreddit.display_name, l.subreddit.title, | |
l.author.name if l.author is not None else "",l.title, | |
u'"'+l.url+u'"')+tuple(urlparse.urlsplit(l.url))+ | |
(l.selftext,) for l in rsaved] | |
json.dump(saved,file("{}.json".format(fbase),"w")) | |
print("Saving {}.csv".format(fbase)) | |
saved=json.load(file("{}.json".format(fbase),"r")) | |
csv.writer(file("{}.csv".format(fbase),"w")).writerows( | |
[[unicode(s).encode("utf-8") for s in sv] | |
for sv in saved]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment