forked from markjosims/aitabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryComments.py
46 lines (38 loc) · 1.05 KB
/
QueryComments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import json
import requests
from time import time
# decorator
def time_exec(f):
def g(*args, **kwargs):
start = time()
f(*args, **kwargs)
end = time()
print(str(f), end-start)
return g
@time_exec
def main():
for i in range(1):
for sub in sub_file(i):
ids = get_comment_ids(sub['id'])
get_comments(ids)
def get_comment_ids(sub_id):
response = requests.get("https://api.pushshift.io/reddit/submission/comment_ids/"+sub_id)
data = response.json()['data']
return data
def get_comments(com_ids):
params = {
"ids": com_ids,
"fields": "body"
}
response = requests.get("https://api.pushshift.io/reddit/comment/search", params=params)
data = response.json()['data']
return data
def sub_file(i):
with open(f"submissions/sub{i}.json", "r") as f:
data = json.load(f)
return data
def write_sub_file(i, data):
with open(f"submissions/sub{i}.json", "w") as f:
json.dump(data, f)
if __name__ == '__main__':
main()