Skip to content

Instantly share code, notes, and snippets.

@kylethebaker
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylethebaker/b81005b36c72c323aa3b to your computer and use it in GitHub Desktop.
Save kylethebaker/b81005b36c72c323aa3b to your computer and use it in GitHub Desktop.
#!/bin/python
import praw
import sys
# recursivly parse comments and MoreComments objects
def parse_comments(comments):
for comment in comments:
if isinstance(comment, praw.objects.MoreComments):
parse_comments(comment.comments())
elif comment.is_root and comment.author is not None:
CONTESTANTS.add(str(comment.author))
# make sure a submission id is given
if len(sys.argv) != 2:
print("usage: {} <submission_id>".format(sys.argv[0]))
sys.exit(1)
# create praw object and get submission contents if we have a valid id
r = praw.Reddit("local ecr giveaway extractor for fun by /u/kylebaked")
parameters = {
"submission_id": sys.argv[1],
"comment_limit": None,
"comment_sort": "old",
"params": {"depth": 1}
}
try:
submission = r.get_submission(**parameters)
except:
print("invalid submission id")
sys.exit(1)
CONTESTANTS = set()
parse_comments(submission.comments)
print(CONTESTANTS)
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment