I'm attempting a simple scraper to dump my saved Reddit posts to a txt file and struggling to get the script to do what I want it to do.
Here's some context. The script below dumps all of my saved post IDs into a text file, each one in its own line.
import praw
import os
import sys
reddit = praw.Reddit(client_id='MY_CLIENT_id',
client_secret='TOP_SECRET',
user_agent='AGENT_HERE',
username='USERNAME',
password='PASSWORD')
#open text file
sys.stdout = open('test.txt', 'w')
# get user saved item ids
for item in reddit.user.me().saved(limit=None):
print(item.id)
# print to file
sys.stdout.close()
This gives me a list of post IDS that looks something like this:
lkj34f
ou456d
ho34oo
5j0vr4
I can then use the below to use each of those IDs to get the actual content I want
submission = reddit.submission(id="dg23y6")
print(submission.title)
print(submission.url)
My first question is - is there a way to open the output file, read each of the lines there and pass it as the id for the submission variable?
I'm sure there's an easier way to get this of course, I have seen several existing scripts like this dumping all content into a nicely formatted HTML file, but I'm not quite there yet, so trying to resolve this challenge using my somewhat limited skillset. I think the most obvious solution would be to use print(actual.command.I.am.missing) in place of print(item.id), but no idea how to find it.
Thanks in advance!