2019-06-14 20:31:11 +00:00
|
|
|
import pdb
|
|
|
|
import praw
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
reddit = praw.Reddit(client_id=os.environ.get('REDDIT_ID'),
|
|
|
|
client_secret=os.environ.get('REDDIT_SECRET'),
|
|
|
|
user_agent='/u/ pynit-tasks',
|
|
|
|
username = os.environ.get('REDDIT_UN'),
|
|
|
|
password = os.environ.get('REDDIT_PW')
|
|
|
|
)
|
|
|
|
|
|
|
|
your_user = reddit.redditor(os.environ.get('REDDIT_UN'))
|
2019-06-17 03:21:56 +00:00
|
|
|
saved_posts = your_user.saved(limit=50)
|
2019-06-14 20:31:11 +00:00
|
|
|
|
|
|
|
posts_to_save = []
|
|
|
|
for link in saved_posts:
|
2019-06-14 21:49:17 +00:00
|
|
|
if hasattr(link, 'is_self'):
|
2019-06-17 03:21:56 +00:00
|
|
|
posts_to_save.append([link.title, link.subreddit.display_name, link.author.name, link.selftext, link.url, link.permalink])
|
|
|
|
elif hasattr(link, 'is_root'):
|
2019-06-14 21:49:17 +00:00
|
|
|
# pdb.set_trace()
|
2019-06-17 03:21:56 +00:00
|
|
|
posts_to_save.append([link.link_title, link.subreddit.display_name, link.author.name, link.body, link.link_url])
|
2019-06-14 21:49:17 +00:00
|
|
|
else:
|
|
|
|
pdb.set_trace()
|
2019-06-17 03:21:56 +00:00
|
|
|
|
2019-06-14 20:31:11 +00:00
|
|
|
with open('data.json', 'w') as outfile:
|
|
|
|
json.dump(posts_to_save, outfile, indent=2)
|