Skip to content

Instantly share code, notes, and snippets.

@ColeMundus
Created November 18, 2017 22:25
Show Gist options
  • Save ColeMundus/327fa2a61266650f2a1d5f0ef5f9f0e7 to your computer and use it in GitHub Desktop.
Save ColeMundus/327fa2a61266650f2a1d5f0ef5f9f0e7 to your computer and use it in GitHub Desktop.
import requests
from pprint import pprint
postID = '7dn55x'
c=requests.get('https://api.pushshift.io/reddit/search/comment/?ids=' + ','.join(requests.get('https://api.pushshift.io/reddit/submission/comment_ids/' + postID).json()['data'])).json()['data']
post = {'post':[]}
for b in c:
if b['parent_id'][3:] == postID:
post['post'].append(b['id'])
for i, b in enumerate(post['post']):
temp = {b:[]}
for x in c:
if x['parent_id'][3:] == b:
temp[b].append(x['id'])
post['post'][i] = temp
for upper_index, b in enumerate(post['post']):
for key, value in b.items():
print(key)
for key_index, i in enumerate(value):
print(' ', i)
temp = {i:[]}
for x in c:
if x['parent_id'][3:] == i:
print(' ', x['parent_id'][3:])
temp[i].append(x['id'])
post['post'][upper_index][key][key_index] = temp
pprint(post['post'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment